wvteijlingen/react-native-themed-styles

NamedStyles typing error with Image component

Opened this issue ยท 3 comments

Hi here ๐Ÿ‘‹

When using a themed style with an Image component I got this error from TS:

Overload 1 of 2, '(props: Readonly<ImageProps>): Image', gave the following error.
    Type 'ViewStyle | TextStyle | ImageStyle' is not assignable to type 'StyleProp<ImageStyle>'.
      Type 'ViewStyle' is not assignable to type 'StyleProp<ImageStyle>'.
        Type 'ViewStyle' is not assignable to type 'ImageStyle'.
  Overload 2 of 2, '(props: ImageProps, context?: any): Image', gave the following error.
    Type 'ViewStyle | TextStyle | ImageStyle' is not assignable to type 'StyleProp<ImageStyle>'.
      Type 'ViewStyle' is not assignable to type 'StyleProp<ImageStyle>'.
        Type 'ViewStyle' is not assignable to type 'ImageStyle'.

If I remove the usage of the NamedStyles typing helper, and keep the S type as it, it works well and I got the correct type from TS.

I can provide a PR if it can help and if this solution is okay for you :)

erkie commented

Is a PR too late to ask for?

No :)
#6

Also it allow to use another types

import { StatusBarStyle } from "react-native";

export const lightTheme = {
	barStyle: "dark-content" as StatusBarStyle,
	backgroundColor: "#ffffff",
	textColor: "#000000",
};