Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Object.entries has the same problem: https://stackoverflow.com/q/60141960


It 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.


It has that same problem actually:

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]`.


> 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]".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: