Answer the question
In order to leave comments, you need to log in
How to fix Property 'item' does not exist on type 'Record' error?
for(let item in classes){
classes.item = 'page'+item
}
Answer the question
In order to leave comments, you need to log in
First: as YavaDev rightly pointed out : classes[item]
.
Secondly: only manually, at your own peril and risk:
for(let item in classes) {
classes[item as keyof typeof classes] = 'page'+item
}
Typescript did not specifically add automatic typing of keys, leaving it simple string
, because due to its structural nature it is impossible to say for sure whether the resulting object (or its prototype) has any other keys other than those specified in its type, and, accordingly, you can not be sure that nothing will break.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question