sindresorhus/type-fest

`Entries` don't works like `ObjectEntries`

オープン

#649 opened on 2023/07/20

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (471 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (12,328 個のスター)
PR merge metrics
 (平均マージ 3d 5h) (30d で 11 merged PRs)

説明

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

コントリビューターガイド