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

TypeScript Error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'

$
0
0

My code is just warning fine, but I'm facing an Error type from Ts while accessing an element in the object using string.

    useEffect(() => {    const categoriesResult: CategoryResult[] = Object.values(      questions?.reduce((r, e) => {        const k = e.category.id;        if (!r[k as keyof object])          return r[k].totalCount += 1;      }, {})    );    setCategories(categoriesResult);  }, [questions]);

The error is in r[k] to be more specific.

Thanks


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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