News for hackers. Stuff that matters.
Re:All I Want for Christmas Is These Seven TypeScript Improv... by noduerme on Sunday December 25, 2022 @11:12PM (#34134508)
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.

Re:All I Want for Christmas Is These Seven TypeScript Improv... by TheCleric on Monday December 26, 2022 @07:07PM (#34143334)
> 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.