Answer the question
In order to leave comments, you need to log in
How to remove the error Element implicitly has an 'any' type because expression of type 'string'?
Good afternoon, tell me how to remove this error
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'IItems'.
No index signature with a parameter of type 'string' was found on type 'IItems'
https://codesandbox.io/s/objective-blackwell-qj3il
Answer the question
In order to leave comments, you need to log in
Because TS doesn't know what exactly is in the variable id
. He only knows that there is some string. And since it id
can be any string, the value ITEMS[0][id]
can also be anything.
You can change your interface by specifying what values id can take
interface IFilters {
id: keyof IItems; // <-- "id" | "filter1" | "filter2"
title: string;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question