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

Type issues with Dynamic StyleSheet property access

$
0
0

I've created a React Native functional component with both light and dark theme styles.

const lightThemeOverrides = StyleSheet.create({ <light_override_styles_here> });const styles = StyleSheet.create({ <styles_here> });

I'm trying to use them in my code with the help of a function:

const themedStyles = (key: string) => {  if (props.theme === 'light') {    return { ...styles[key], ...lightThemeOverrides[key] };  } else {    return styles[key];  }  };

I use this function in my JSX like so: <View style={themedStyles('popup')}>

But my ts linter is complaining, that Element implicitly has an 'any' type because type '{ popup: { backgroundColor: string; }; text: { color: string; }; }' has no index signature.

Any idea how to fix this?All tips will be highly appreciated.


Viewing all articles
Browse latest Browse all 6214

Trending Articles



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