microsoft / microsoft/TypeScript
Mapped tuples types iterates over all properties
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.2.0-dev.20181019
Search Terms: mapped tuples reify
Code
type Foo = ['a', 'b'];
interface Bar
{
a: string;
b: number;
}
type Baz = { [K in keyof Foo]: Bar[Foo[K]]; }; // Expected Baz to be [string, number]
Expected behavior: Baz should be [string, number]
Actual behavior: Type '["a", "b"][K]' cannot be used to index type 'Bar'.
Related Issues: https://github.com/Microsoft/TypeScript/issues/25947
Given the Mapped tuple types feature (#25947). I'd expect the code above to work cleanly.
However, I still need to do:
type WorkingBaz = { [K in Exclude<keyof Foo, keyof any[]>]: Foo[K] extends keyof Bar ? Bar[Foo[K]] : never; } & { length: Foo['length']; } & any[];
To have an equivalent type. As far as I understand, the "K" in a mapped type on a tuple should iterate only on numeric keys of this tuple. Therefore, Foo[K] should always be a valid key for Bar...
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue 内の最小限の TypeScript 再現コードから始め、Related Issue #25947 と比較してください。コンパイラーでの mapped tuple 型のチェックを追跡します。Baz が Exclude/intersection の回避策なしで [string, number] として受け入れられれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100