type-fest
type-fest copied to clipboard
`Entries` don't works like `ObjectEntries`
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.
I would say it's a bug.
I think this is a TypeScript bug, reported to ts https://github.com/microsoft/TypeScript/issues/56921