node.js - TypeScript compiler does not throw error on missing declaration -
i have found strange case in nodejs project. try describe problem here believing there's simple option in tsconfig.json
case. use typescript v1.7.3.
file test1.ts
contains variable declaration:
// test1.ts let = 1;
file test2.ts
contains improper variable usage:
// test2.ts console.log(a);
tsconfig.json
looks this:
// tsconfig.json { "compileroptions": { "module": "commonjs", "target": "es5" } }
compiler not throw error me using undeclared variable a
. if try export other variable, b
expected error:
// test1.ts let = 1; export let b = 2;
compiler:
error:(1, 13) ts2304: cannot find name 'a'.
how can make compiler emit error in first case? i've found out in project removed variable , failed in runtime, not compile time.
this unfortunate consequence of fact files without kind of export or import considered "script" files compiler. compiler assumes script files operate in global scope, , stitched together. without --outfile
being specified, won't able whether variable declaration occur after usage.
one workaround add a
export {};
statement files.
Comments
Post a Comment