Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

fast-memoize type TextStyles react native

$
0
0

I am trying this library fast-memoize to generate style for TextReact-Native.

On the code below, use the color parameter to generate the string color.

import { StyleSheet, TextStyle } from 'react-native';import memoize from 'fast-memoize';import { Colors } from '../../../Constants';import type { Styles, Color } from './types';export default StyleSheet.create<Styles>({  textStyles: memoize(    (color: Color): TextStyle => ({      color: color ? Colors[color] : Colors.BLACK,      fontSize: 12,    }),  ),});

On this code, will define the type of the Styles.

import { TextStyle } from 'react-native';import { Colors } from '../Constants';export type Styles = {  textStyles: (color: string) => TextStyle;};

But it will return an error when checking the type code.

Type 'Styles' does not satisfy the constraint 'NamedStyles<any> | NamedStyles<Styles>'.  Type 'Styles' is not assignable to type 'NamedStyles<Styles>'.    Types of property 'textStyles' are incompatible.      Type '(color: string) => TextStyle' is not assignable to type 'ViewStyle | TextStyle

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>