Back to questionsWhat happens if
JuniorTheoryCommon
What happens if hello.ts holds this code and you run tsc hello.ts, then node hello.js?
let count: number = 1;
count = "two";
console.log(count);tsc reports an error, and hello.js prints two
- Expecting
tscto write no JavaScript after an error: it writeshello.jsanyway unless the--noEmitOnErrorflag is set. - Expecting the annotation
numberto turn "two" into a number at run time:hello.jshas no types, so the string is printed.
- How do you make
tscrefuse to write JavaScript while the code has errors? - Why can't a type annotation check a value that arrives while the program runs?