react-native-themed-styles icon indicating copy to clipboard operation
react-native-themed-styles copied to clipboard

Type error in strict mode

Open mxmtsk opened this issue 5 years ago • 0 comments

Hi,

thanks for the package, love the approach. I'm using it with TypeScript in strict mode. When I follow your example and use createStyles I get a type error at theme:

Parameter 'theme' implicitly has an 'any' type.

export default createStyles(theme => ({
  container: {
    backgroundColor: theme.backgroundColor,
    flex: 1
  },
}))

I've fixed it by assigning a type each time:

type ThemeValues = { [identifier: string ]: number | string };
export default createStyles((theme: ThemeValues) => ({
  container: {
    backgroundColor: theme.backgroundColor,
    flex: 1
  },
}))

Another error happens when using the hook to get the styles:

const Container: React.FC<IContainer> = ({ children }) => {
  const [ styles ] = useTheme(themedStyles);
  return (
    <View style={styles.container}>
      {children}
    </View>
  );
}

Property 'container' does not exist on type 'NamedStyles<NamedStyles> | NamedStyles<NamedStyles>'. Property 'container' does not exist on type 'NamedStyles<NamedStyles>'.

I'm not the most advanced TypeScript user yet so I wonder if this could be fixed in the library directly.

mxmtsk avatar Jan 02 '20 13:01 mxmtsk