microsoft / microsoft/TypeScript

flag to check for type-unreachable code

オープン
#45,267 コメント 13 件 リアクション 4 件 担当者 0 名 GitHub で見る

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

feature request

the allowUnreachableCode flag (when disabled) only checks for code that's syntactically unreachable. however, the check doesn't work at all when looking at types.

i propose an additional flag (as @RyanCavanaugh suggested keeping these two concerns separate, see https://github.com/microsoft/TypeScript/issues/45267#issuecomment-901297945) that checks for code that the type checker believes is unreachable. for example:

declare function foo(): never

const a = foo()
console.log(1) //no error

foo()

console.log(1) //error

assertNever

in order to allow the assertNever pattern, the flag could still allow unreachable code where an argument of type never is passed, but not code after never is returned. this way, the following code would still be valid:

declare function assertNever(value: never): never
declare const foo: 1|2|3
switch(foo) {
    case 1:
        break
    case 2:
        break
    case 3:
        break
    default:
        assertNever(foo)
}
🔎 Search Terms

unreachable code

⏯ Playground Link

Playground link with relevant code

💻 Code
if (false) console.log("asdf") //error
if (false as false) console.log("asdf") //no error

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

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

はじめの一歩

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

調査の方向性

リンクされている TypeScript Playground から始め、既存の allowUnreachableCode の動作を使って両方の例を再現します。これらのケースに関連する型チェックと到達不能コードの診断を読み、その後、never を返す場合と assertNever の呼び出しに対するフラグの動作を定義します。提案された型ベースの到達不能チェックと例外が、合意されたコンパイラテストでカバーされれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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