Courses / Node.js: From First Script to Production / Chapter 22
Module 9 · Tests, types and operations · Chapter 22 of 27
TypeScript for Node: Type Stripping, tsconfig and Typed Handlers
Builds on npm and Package Management: Dependencies, Versions and Lockfiles and Production APIs: Validation, Error Shapes, Idempotency and Fastify. Next up: Observability: Structured Logs, Metrics and Traces.
Part 1 · Running TypeScript in Node
What TypeScript adds
Most Node teams write TypeScript for the server, and Node can now run it directly. This lesson covers what TypeScript is and how Node runs a .ts file with no build step.
TypeScript is JavaScript with type annotations. You write price: number to say a value is a number, and a tool called the type checker reads the whole program and reports places where the claims do not fit. A function that expects a number and is called with a string is flagged before the program runs. The checker is tsc, the TypeScript compiler.
Types exist only for the checker. Neither Node nor a browser knows what a type is, so before code runs the annotations must be removed. Removing them is called erasing the types, and what is left is plain JavaScript. Historically that needed a build step. Since Node 22.6 the runtime can do the erasing itself, which is called type stripping. The version history below comes from the Node documentation; the runs in this lesson used Node 24.18.
| Node line | What changed |
|---|