Tooling & Compiler
TypeScript does not run — it compiles. Neither the browser nor Node.js understands a single type annotation; between the .ts file and running code always sits the tsc compiler, which checks types and emits plain JavaScript with every trace of types gone. Understanding TypeScript's tooling means understanding that one-way door: types live only at compile time and are erased before anything runs.
The rest of the topic is about steering that compiler. tsconfig.json is the single control panel: it decides which JavaScript dialect to target, which module system to use, and where to put the output. The strict flag is an umbrella that turns on strict checks all at once. And ambient declarations (.d.ts) are how you tell the compiler about code it cannot see — globals and plain-JS libraries. The map below runs from invoking tsc to fine-tuning it.
Topic map
- Compiling with tsc — what
tscdoes, why types are erased on emit, and how type-checking is separate from bundling. - tsconfig.json — the compiler's control panel:
target,module,outDir,rootDir,lib, and howinclude/excludepick files. - Strict Mode —
strictas an umbrella overstrictNullChecks,noImplicitAny, and others; all checks are compile-time. - Ambient Declarations —
declare,.d.tsfiles, and@typespackages to describe code the compiler cannot see.
Common traps
| Mistake | Consequence |
|---|---|
| Thinking types stay in the output | tsc erases all types; at runtime there is no interface or annotation — instanceof on an interface is impossible |
Assuming the browser runs .ts directly | A compile step is required; without tsc (or another transpiler) the code will not run |
Relying on tsc as a bundler/minifier | tsc only type-checks and transpiles; bundling and optimization are separate tools |
Treating strict as one check | It is an umbrella over a family of flags (strictNullChecks, noImplicitAny, …) — all enabled at once |
Expecting strictNullChecks to add runtime checks | All checks are compile-time only; nothing is inserted into the emitted JS |
Confusing noImplicitAny with banning any | Explicit any is still allowed; the flag only complains about an implicitly inferred any |
Thinking a .d.ts holds implementation | A .d.ts is type signatures only; there is no code and it emits nothing |
Assuming declare creates a value | declare only promises the compiler the value exists elsewhere; it creates nothing itself |
Interview relevance
Tooling is asked to separate those who "write types" from those who understand that types are gone at runtime. A candidate who explains tsc as "checked the types, erased them, emitted JavaScript" sets the right model immediately.
Typical checks:
- What
tscdoes with types and why they are absent from the output. - The role of
tsconfig.jsonand the meaning oftarget/module/outDir. - What
strictis and why it is an umbrella, not a single check. - Why
declareand.d.tsexist and how to type an untyped library.
Common wrong answer: "TypeScript checks types at runtime". That opens the discussion of type erasure: checks happen only at compile time, and plain JavaScript with no annotations is what actually runs.