microsoft / microsoft/TypeScript
False positive for "Unreachable code detected" for code following `switch`/`case` with `allowUnreachableCode: false`
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
"false positive allowUnreachableCode"
"allowUnreachableCode case statement"
"Unreachable code detected case statement"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
switch/case
⏯ Playground Link
💻 Code
type Foo = "bar" | "baz"
const fn = (value: Foo): number => {
switch(value) {
case "bar":
return 1;
case "baz":
return 2;
}
return assertNever("nope!");
}
🙁 Actual behavior
return assertNever("nope!");
is highlighted as "Unreachable code detected". The docs, however, state:
This does not affect errors on the basis of code which appears to be unreachable due to type analysis.
🙂 Expected behavior
No error. This should be the same as the other case form, the if form, and various similar constructs where even though it's allegedly exhaustive, that's just based off of type information (I would like to have a runtime assertion in this case).
Additional information about the issue
Possibly related to: https://github.com/microsoft/TypeScript/issues/18882
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている TypeScript Playground の再現例から始め、switch/case の例を、報告で説明されている他の case 形式と比較してください。関連している可能性のある issue #18882 を確認し、そのうえで、網羅的な switch の後にあるランタイムアサーションが到達不能として報告されなくなっていることを検証してください。同時に、到達不能コードに対する既存の動作が維持されていることも確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100