type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

`Entries` don't works like `ObjectEntries`

Open SettingDust opened this issue 1 year ago • 2 comments

playground The type of generic is lost. And it's useful when I want to make the result respect the key-value pair instead of a record with union keys-values So, maybe export the ObjectEntries. Or is it a bug?

function test<T extends Record<string, unknown>>(input: T) {
  for(const entry of Object.entries(input) as ObjectEntries<typeof input>) {
    type key = typeof entry[0] // keyof T
    type value = typeof entry[1] // T[keyof T]
  }

  for(const entry of Object.entries(input) as Entries<typeof input>) {
    type key = typeof entry[0] // string
    type value = typeof entry[1] // unknown
  }
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

SettingDust avatar Jul 20 '23 13:07 SettingDust

I would say it's a bug.

sindresorhus avatar Jul 20 '23 23:07 sindresorhus

I think this is a TypeScript bug, reported to ts https://github.com/microsoft/TypeScript/issues/56921

Emiyaaaaa avatar Jan 02 '24 06:01 Emiyaaaaa