TypeScript compilation and type stripping
Local baseline: Node.js 22.16.0. Actual TypeScript source execution, independent tsc check. TypeScript 5.8.3; no third-party packages.
Try the local example
const quantity: number = 3;const unitCents: number = 125;function total(q: number, price: number): number { return q * price; }console.log(total(quantity, unitCents));Run node --experimental-strip-types main.mts in a disposable directory with the files shown. Expected standard output:
375An experimental warning is expected on stderr for this local version.
Check independently with tsc --strict --noEmit --target es2022 --module nodenext --allowImportingTsExtensions main.mts.
How it works
An annotation describes an expected value; it does not convert it. Node 22.16.0 supports experimental stripping of erasable syntax, enabled by default in this release. The explicit flag in the example documents the intended mode. The compiler command tsc --strict --noEmit --target es2022 --module nodenext main.mts checks without producing files. A separate emit workflow can compile JavaScript before running it. Enums and parameter properties require transformation; native stripping is not a general compiler and does not apply tsconfig path aliases. Use a reviewed transpiler when needed.
Common mistake
Do not interpret successful execution as type safety. An annotation of number cannot make an external string a number. Check unknown input at runtime.
Practice
Change quantity to a string and run the compiler check before executing again. Explain why a type error can coexist with executable JavaScript.
Documentation: primary source. Candidate lookup: node-typescript-compilation-and-type-stripping-lookup. Prerequisite: node-nest-testing (platform route unverified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
TypeScript compilation and type stripping — knowledge check
Apply the lesson’s contracts and identify common boundary mistakes.
What does native stripping verify?
Which command checks types without emitting JavaScript?
A JSON field arrives as a string despite a number annotation. What is required?