What TypeScript checks
Concept and syntax
TypeScript checks how values are used before the program runs. A type describes which values are permitted: number allows numbers, not text. In let seats: number = 4, the colon introduces a type annotation; the JavaScript assignment still creates the value. Use a compiler check to find incompatible assignments, then run JavaScript to observe actual behavior. Static checks do not validate arbitrary external data or guarantee that a program never throws.
Working example
Compile standalone examples in a fresh directory with tsc --strict --target ES2022 --module commonjs --noEmitOnError main.ts, then node main.js.
Expected output (one line per log):
6Common mistake
Intentionally invalid; check this snippet separately. Do not run it.
Expected compiler diagnostic: TS2322. The second assignment supplies text where the annotation requires a number. A type error is reported during checking, rather than a required JavaScript exception.
Practice and recap
Change seats to another number, then try a text assignment. Compare the check with what JavaScript would do if no checker ran.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
What TypeScript checks — knowledge check
Check the concept, apply it to a new choice, and interpret a compiler diagnostic.
When does a static type check take place?
Which task still needs runtime logic?
Why is the second assignment rejected?
let seats: number = 4;seats = "six";