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

React-Native TypeScript: error when passing in variable to stylesheet object

$
0
0

Here is the style I'm using and how I'm using it

style={styles.input(isPasswordSelected)}

const styles = StyleSheet.create({  input: (isPasswordSelected: boolean) => ({    height: 40,    marginHorizontal: 20,    marginVertical: 7,    padding: 10,    borderRadius: 10,    backgroundColor: '#c9c9c9',    borderWidth: 1,    borderColor: isPasswordSelected ? '#458ae6' : 'transparent',  }),});

This normally works in JS without issues but in ts I get this error

Type '(isPasswordSelected: boolean) => { height: number; marginHorizontal: number; marginVertical: number; padding: number; borderRadius: number; backgroundColor: string; borderWidth: number; borderColor: string; }' is not assignable to type 'ViewStyle | TextStyle | ImageStyle'.ts(2322)

it seems to think that the entire function is my type declaration.

The error is just in the IDE, code runs fine. Possibly able to solve with an update to my tsconfig.json

I've tried changing the typing to style typings but couldn't get the error to go away


Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images