microsoft / microsoft/TypeScript
`keyof` on homomorphic mapped type over an array thinks keys are function types
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
Creating a mapped type (where each value is just the key - { [K in keyof T]: K }) when applied over a generic type T, where T has been passed as an array type, somehow manages to resolve the keys of an array as functions. I've read the FAQ about homomorphic mapped types but I can't imagine the K in K in keyof T ending up as a function type - no matter what the T eventually becomes.
🔎 Search Terms
keyof, array, types, type constructors
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about homomorphic mapped types
Tested on 3.9.7, 4.2.3.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Keys<T> = {
[K in keyof T]: K;
}[keyof T];
type GT = Keys<string[]>;
// ^ Hover here. Keys are functions ???

🙁 Actual behavior
Keys applied over an array, returns a union of functions.
🙂 Expected behavior
Keys applied over an array, should return the property names of the array.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground で、string[] を使った Keys の例の動作を再現します。まず、コンパイラーが配列に対して keyof と同型写像型をどのように処理するかを調査します。Keys<string[]> が関数のユニオンではなく、配列のプロパティ名のユニオンに解決されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100