sindresorhus/type-fest

`Entries` don't works like `ObjectEntries`

Offen

#649 geöffnet am 20.07.2023

 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (471 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (12.328 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 3T 5h) (11 gemergte PRs in 30 T)

Beschreibung

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
  }
}

Contributor Guide