microsoft / microsoft/TypeScript
[BUG] union type generic extends child class with generic method
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: all, tested from 3.3 to 4.2
Search Terms: union type generic extends child class with generic method
Code
class A<GValue> {
a<GKey extends GValue>(value: GKey): void {}
}
class B<GValue> extends A<GValue> {
a<GKey extends GValue>(value: GKey): void {}
}
const a1: (('a' | 'b') extends any ? true : false) = true;
const a2: (('a') extends any ? true : false) = true;
const a3: (B<'a' | 'b'> extends A<any> ? true : false) = true; // error before v3.7
const a4: (B<'a'> extends A<any> ? true : false) = true; // error
const a5: (B<'a'> extends B<any> ? true : false) = true;
type Constrained<G extends A<any>> = true;
const a6: Constrained<A<'a'>> = true; // ok
const a7: Constrained<B<'a' | 'b'>> = true; // ok
const a8: Constrained<B<'a'>> = true; // error
Details:
-
a1 and a2 shows us that a string or an union of string extends any => legit
-
a3 shows us that it's still true, except before typescript 3.7 => true seems legit
-
a4 creates an error because
(B<'a'> extends A<any> ? true : false)is actually false => bug, true expected.
So, an union is true, but not a single value. -
a5 is true which is correct
-
a6, a7 and a8 shows the same but with a type constraint
Notes:
a3has not the same behavior between before and after v3.7- the bug appears only when we have a generic type on a method which extends another generic type coming from the class
Playground Link: playground link
Related Issues: this bug is pretty hard to reach and to describe, I was not able to find any related issue.
But a good start could be to search from a fix or update from the 3.6 to the 3.7, as a3 has not the same behavior between these versions.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている TypeScript の repro と Playground リンクから始め、提案されているとおり 3.6 と 3.7 のコンパイラーの動作を比較します。A を拡張する B のジェネリックメソッドについて、型チェックの経路を追跡します。a4 と a8 のケースが true を受け入れ、既存の a5、a6、a7 の動作が正しいままであれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100