microsoft / microsoft/TypeScript

Type Guards are no longer working correctly all the time

オープン
#54,178 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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

A simple example

💻 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている TypeScript Playground から始め、TypeScript 4.9.5 と 5.0.4 の両方で Foo の例を再現します。isReady() の型ガードによって x の型がどのように絞り込まれるかを追跡し、その後、条件によって型が Foo に変わることを、以前の動作を後退させずに確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。