microsoft / microsoft/TypeScript
Type narrowing of `super` when using `this`
オープン
まだ誰も着手していません。
Bug
Domain: This-Typing
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
super, this, class
🕗 Version & Regression Information
Nightly
⏯ Playground Link
💻 Code
class Animal<T> {
eat<T>(this: Animal<T>) {
throw new Error('This doesnt matter');
}
}
class Dog<T> extends Animal<T> {
eat<U>(this: Dog<U>) {
super.eat(); // The type is Animal<T>.eat<T>(this: Animal<T>): void
// The type should be Animal<U>.eat<U>(this: Animal<U>): void
}
}
🙁 Actual behavior
super.eat() is typed as Animal<T>.eat<T>(this: Animal<T>): void
🙂 Expected behavior
super.eat() should be typed as Animal<U>.eat<U>(this: Animal<U>): void since this is declared as Dog<U> which is a subclass of Animal<U>.
One can workaround this by writing super.eat<U>(), but the signature then becomes goofy (it becomes Animal<T>.eat<U>(this: Animal<U>): void)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の TypeScript Playground から始め、ジェネリッククラス Animal と Dog における super.eat() の現在の型と期待される型の違いを再現してください。super のプロパティアクセスにおける this 型のコンパイラの処理を追跡し、その後リグレッションテストを追加して、明示的な型引数を必要とせずに super.eat() が U 固有の型を保持することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 38/100