microsoft / microsoft/TypeScript
Type Guards are no longer working correctly all the time
オープン
まだ誰も着手していません。
Domain: This-Typing
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
Type Guard
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
💻 Code
declare class Foo<Stuff extends boolean> {
stuff: Stuff extends true ? string : string | undefined;
isReady(): this is Foo<true>
}
declare const x: Foo<boolean>;
if(x.isReady()) {
x
//^? - const x: Foo<boolean>
// Should be Foo<true>
}
🙁 Actual behavior
The Type Guard didn't change the type, which is unintuitive behavior.
🙂 Expected behavior
The method should act as a type guard and change the type
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている TypeScript Playground から始め、TypeScript 4.9.5 と 5.0.4 の両方で Foo の例を再現します。isReady() の型ガードによって x の型がどのように絞り込まれるかを追跡し、その後、条件によって型が Foo に変わることを、以前の動作を後退させずに確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100