sindresorhus/type-fest

`Entries` don't works like `ObjectEntries`

Open

#649 建立於 2023年7月20日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)TypeScript (12,328 star) (471 fork)batch import
bughelp wanted

描述

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

貢獻者指南

`Entries` don't works like `ObjectEntries` · sindresorhus/type-fest#649 | Good First Issue