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

Styled component throws weird typescript error

$
0
0

I have styled components and typescript in my RN Project

Typescript is throwing a weird error in one of my files, it says Element implicitly has 'any' type because expression of type 'string' can't be used to index 'ColorKeyType'

The affected code, the error is at the return theme.colors[color] part

const StyledText = styled(Text)<TextStyleProps>`  color: ${({ color, theme }) => {    if (color) {      return theme.colors[color] || color;    }    return theme.colors.text;  }}`;

My theme color is typed like:

interface ColorKeyType {  primary: string;  ... more colors like the one above}

then I use the type like:

{    colors: ColorKeyType;    fonts: {      families: {        primary: { [key in FontFamilyType]: string };      };      fontSize: { [key in FontSizeType]: number };      letterSpacing: number;    };}

Thanks in advance for any possible solutions!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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