7 ms·
Object.entries has the same problem: https://stackoverflow.com/q/60141960 https://stackoverflow.com/q/60141960
by modestygrime 3y ago
Object.entries has the same problem: https://stackoverflow.com/q/60141960 https://stackoverflow.com/q/60141960
- Dylan16807 3y agoIt has some of the same problems. It doesn't have the problem of being unable to read obj[key] because typescript doesn't realize it's the same object.
- modestygrime 3y agoIt has that same problem actually: https://news.ycombinator.com/item?id=36458300 https://news.ycombinator.com/item?id=36458300 And according to the article, the issue isn't that TS doesn't realize it's the same object, it's that the object might have more keys than what is declared in your interface. Perhaps what you meant to say is that you can directly use `val` instead of `obj[key]`.
- Dylan16807 3y ago> And according to the article, the issue isn't that TS doesn't realize it's the same object, it's that the object might have more keys than what is declared in your interface. The main issue at hand was inability to use `options[key]`. "the object might have more keys" was a possible issue, and was the reason typescript was blocking access to `options[key]`, but it wasn't the main problem. > It has that same problem actually: > Perhaps what you meant to say is that you can directly use `val` instead of `obj[key]`. How is that different from what I said? Because you can directly use `val`, and because that's better than `obj[key]` anyway, you "don't have the problem of being unable to read obj[key]".