microsoft / microsoft/TypeScript
Some types are incorrectly assignable from a generic distributive conditional type
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.5.1
Search Terms: generic conditional distributive assignable from
Code
type Keys<T extends object> = T extends unknown ? keyof T : never;
function f<T extends object>(keys: keyof T, moreKeys: Keys<T>) {
keys = moreKeys;
}
// With this instantiation, `keys` is typed 'a',
// and `moreKeys` is typed 'a' | 'b' | 'c'. The latter
// should not be assignable to the former, but it happens
// in the generic context of the function `f`.
f<{ a: any, b: any } | { a: any, c: any }>('a', 'b');
Expected behavior:
Keys<T> should not be assignable to keyof T since Keys<T> is distributive and will produce a different type than keyof T when T is a union type.
Note that the reverse of this assignment, moreKeys = keys, errors for this exact reason; without a concrete T, it’s hard to tell what the relationship should be, so we simply have no relationship in place.
Actual behavior:
The unsafe assignment is allowed.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた Playground にあるジェネリックな分配条件型の例を再現することから始めます。ジェネリックコンテキストでの代入可能性について、型チェックの経路を追跡し、その後、安全でない代入と、記載されている逆方向の代入の挙動を対象とする回帰テストを追加します。'b' を指定した呼び出しが、Keys を keyof T に代入できないため拒否されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100