Hey @artxe2 !
I think the issue lies more in the for...of/for...in loop, as it returns a string for a key variable. If you typecast it, everything will be fine 🙂
for...of
for...in
key
for (let key of Object.keys(obj)) { const typeKey = key as keyof typeof obj; obj[typeKey].func(); // ✅ if (obj[typeKey]) { obj[typeKey].func(); // ✅ } } for (let key in obj) { const typeKey = key as keyof typeof obj; obj[typeKey].func(); // ✅ if (obj[typeKey]) { obj[typeKey].func(); // ✅ } }
We're a place where coders share, stay up-to-date and grow their careers.
Hey @artxe2 !
I think the issue lies more in the
for...of/for...inloop, as it returns a string for akeyvariable. If you typecast it, everything will be fine 🙂