Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entries don't works like ObjectEntries #649

Open
SettingDust opened this issue Jul 20, 2023 · 2 comments
Open

Entries don't works like ObjectEntries #649

SettingDust opened this issue Jul 20, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@SettingDust
Copy link

SettingDust commented Jul 20, 2023

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
@sindresorhus
Copy link
Owner

I would say it's a bug.

@sindresorhus sindresorhus added bug Something isn't working help wanted Extra attention is needed labels Jul 20, 2023
@Emiyaaaaa
Copy link
Collaborator

I think this is a TypeScript bug, reported to ts microsoft/TypeScript#56921

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants