4 ms·
Deducing types from Object.entries would be pretty awesome. That would feel like black magic. I had a lot of fun messing around with Copilot seeing if it could
by noduerme 4y ago
Deducing types from Object.entries would be pretty awesome. That would feel like black magic. I had a lot of fun messing around with Copilot seeing if it could guess exactly that kind of thing, sometimes directly from
raw results of SQL queries once it understood the DB table structure. Occasionally it could. (Nonetheless, I don't feel like paying for it).
Still, it feels dangerous to be able to feed a generic object method in and expect the return to be typed based on a previous typing of the composite instances. Or maybe it feels like something that should always pass a compile check - because Object.entries can always be any - and only fail at runtime. Even if it was a feature, it's something I wouldn't implicitly trust a compiler to catch all edge cases of.
- TheCleric 4y ago> Deducing types from Object.entries would be pretty awesome. That would feel like black magic. Not really. Typescript already has the keyof keyword. For some reason though Object.entries(T) returns string[] when it could easily return keyof typeof T I've had to write a helper function that essentially does this for you with a generic and a cast, but it feels unnecessary.