Here is a simplified example of the issue I am facing:
const testCase = {a:{b:"result"}}
for (const i in testCase) {
console.log("i", i)
for (const j in testCase[i]){
console.log("j", j)
}
}
Encountering this error:
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ a: { b: string; }; }'.
No index signature with a parameter of type 'string' was found on type '{ a: { b: string; }; }'.
5 for (const j in testCase[i]){
To overcome this, I have been casting i
as a keyof typeof testCase
.
const testCase = {a:{b:"result"}}
for (const i in testCase) {
let typedIndex = i as keyof typeof testCase
console.log("i", i)
for (const j in testCase[typedIndex]){
console.log("j", j)
}
}
Is there a more efficient way to handle this issue, or am I deviating towards an anti-pattern by not defining a specific structure for testCase
?