- type-fest に ObjectEntries が入った
- 組み込みの Object.entries() の型定義が改善されない理由の一般的な説明
- enum のせいで人類は Object.entries() に完璧な型付けをできない
- そんなわけで今日も乱立する Object.entries() の型定義
type-fest に ObjectEntries が入った
2026/10/14、遂に type-fest に ObjectEntries (ObjectEntry) が入ったようですね(めでたい
このコミットだけ見て、個人的には「結構割り切ったなぁ~」と言う印象を受けました *1
export type ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
ただ、main ブランチの実装が異なっていたので history を確認したところ、直後のコミットで以下の定義に変更されていました
なるほどなるほど、頑張ってますね
export type ObjectEntry<BaseType extends object> = // `never` has every key, so it would otherwise give a pair for each kind of key. The check is not distributive, so a generic `BaseType` is not read through its constraint. [BaseType] extends [never] ? never : { // `Object.entries` yields every key as a string, because every property key is a string or a symbol at runtime, so a numeric key arrives as its string form. A string key is kept as it is, so a string enum or a branded key keeps its type. [Key in Exclude<keyof BaseType, symbol>]: [(Key & string) | `${Key & number}`, BaseType[Key]] // A mapped type indexed by its own keys, rather than a conditional type, pairs each key with its own value and still resolves for a generic `BaseType`. A type with only symbol keys has no entry at all, because `Object.entries` never yields one. }[Exclude<keyof BaseType, symbol>];
*1:関連する issue を subscribe してたので、このコミットで close されたメールで飛んできた



