sindresorhus/type-fest

`Entries` don't works like `ObjectEntries`

Aberta

#649 aberto em 20 de jul. de 2023

 (4 comentários) (0 reação) (0 responsável)TypeScript (471 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (12.328 estrelas)
Métricas de merge de PR
 (Mesclagem média 3d 5h) (11 fundiu PRs em 30d)

Description

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

Guia do colaborador