Uncaught compiler error: Block-scoped variable from import used before its declaration.

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, typescript
領域
compilers

調査の方向性

まず、報告された TypeScript 2.4 のケースを tsc で再現し、issue で説明されている const または let のバリアントと比較します。コンパイラーが宣言前の import alias と、それが参照する namespace をどのように扱うかを追跡します。完了条件は、報告されたコードが実行時に失敗する JavaScript を生成するのではなく、期待されるコンパイル時診断を受け取ることです。

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

説明

Bug Domain: Binder

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

Input Typescript

namespace A {
    export namespace B {
        export class C {
            constructor()
            {
                console.log("Hello World");
            }
        }
    }
}

import myA_B = myA.B;
import myA = A;

new myA_B.C();

Output JavaScript from tsc

var A;
(function (A) {
    var B;
    (function (B) {
        var C = (function () {
            function C() {
                console.log("Hello World");
            }
            return C;
        }());
        B.C = C;
    })(B = A.B || (A.B = {}));
})(A || (A = {}));
var myA_B = myA.B;
var myA = A;
new myA_B.C();

Expected behavior:
Expected the typescript compiler error Block-scoped variable 'myA' used before its declaration.

Actual behavior:
Runtime error of Uncaught TypeError: Cannot read property 'B' of undefined

Comments
The typescript compiler will catch this if I use const or let keywords instead, so I expected the same error handling for import in this case.

My team prefers using import over const or let when we can for performance of not pulling in javascript code from external files when we are only referencing types.

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

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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