Transpilation, targets and type checking
Quick answer
A compiler can transform newer syntax into an older output target. TypeScript also checks types, but type annotations are not runtime validators and target selection does not install missing browser APIs.
Tooling examples
Example 1. Context: projects/compiler-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
tsc -p tsconfig.jsonnode dist/price.jsExpected observation: 12
Example 2. Context: projects/compiler-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
tsc -p tsconfig.bad.jsonExpected observation: Nonzero exit; no new dist-bad output in a clean copy.
How the tooling works
The supplied compiler-lab uses tsc 5.8.3 and a JavaScript source with checkJs enabled. Its tsconfig sets target ES2017, module CommonJS, strict, sourceMap and noEmitOnError. Optional chaining is lowered for this target. noEmitOnError prevents new emission on a reported error, but does not remove earlier artifacts; use a clean output directory. Syntax transformation and polyfills are different tasks. Test the target environment, especially for newer runtime methods.
Common mistakes
Do not confuse successful compilation with compatibility of every API, or a successful build with runtime input validation.
Practice
Compile the example and inspect the emitted optional-chaining replacement. In a disposable copy add a type error and confirm a nonzero exit and no fresh output.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Transpilation, targets and type checking — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Does lowering optional chaining syntax automatically provide missing runtime APIs?
What does noEmitOnError prevent?
Why use a clean output directory for a build?
In Transpilation, targets and type checking, what is the expected observation for example 1 in its documented setup? tsc -p tsconfig.json node dist/price.js
In Transpilation, targets and type checking, what is the expected observation for example 2 in its documented setup? tsc -p tsconfig.bad.json