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

NamedStyles typing error with Image component

Open CPatchane opened this issue 4 years ago • 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 :)

CPatchane avatar Jul 09 '20 20:07 CPatchane

Is a PR too late to ask for?

erkie avatar Nov 27 '20 13:11 erkie

No :) https://github.com/wvteijlingen/react-native-themed-styles/pull/6

CPatchane avatar Nov 28 '20 21:11 CPatchane

Also it allow to use another types

import { StatusBarStyle } from "react-native";

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

indapublic avatar Aug 24 '22 08:08 indapublic