microsoft / microsoft/TypeScript
Use before declaration errors when using let statements within a switch case
オープン
まだ誰も着手していません。
Bug
Domain: Binder
Effort: Difficult
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 2.5.3
Code
function test(value) {
switch (value) {
case 1:
let foo = 10;
break;
case 2:
foo = 20; // Runtime ReferenceError: foo is not defined
break;
default:
}
}
test(2);
tsc --target es2015 (or higher)
Expected behavior:
This should probably produce a compile time error: Block-scoped variable 'pen' used before its declaration. on reference to foo in case 2.
Actual behavior:
The code type-checks and compiles fine, however, when running the es2015 transpiled output, you will receive a ReferenceError error at runtime. Ideally this type of error could be caught at compile time.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された switch-case の例を TypeScript 2.5.3 で開始し、--target es2015 以上を指定してコンパイルします。case 節をまたぐブロックスコープの let 宣言と参照について、型チェックの経路を追跡します。case 2 の foo への参照が、コンパイル時にブロックスコープ変数の宣言前参照の診断を生成し、実行時の ReferenceError にコンパイルされないことが完了の条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100