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

Accessing react native StyleSheet member via dynamic key string in typescript

$
0
0

I have this stylesheet:

const styles = StyleSheet.create({  primary: {},  secondary: {},})

And I would like to access the keys with dynamically composed strings.

<View style={styles[props.type]}/>

This is when TS complains (but the code runs just fine as one would expect):

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ primary: { }; secondary: { }'.  No index signature with a parameter of type 'string' was found on type '...'.ts(7053)

How could I nudge TS in the right direction and make it happy?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



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