TypeScript Doesn't Run Directly in Node or Browsers
What you'll learn: Why TypeScript code must be transformed before your computer can actually execute it.
The Core Reality
Here's a fundamental truth about TypeScript: no runtime environment natively understands .ts files. Neither Node.js nor web browsers can execute TypeScript directly. They only understand JavaScript.
Think of TypeScript as a blueprint written in a special architect's language. Before builders (Node.js or browsers) can construct anything, someone must translate those blueprints into the standard construction language everyone understands—JavaScript.
Why This Matters
When you write a .ts file, you're writing in a language that adds type annotations, interfaces, and compile-time checks. But at execution time, all those extra features need to disappear. The runtime doesn't care about your type definitions—it just wants plain JavaScript it can run.
This is where the tsc command (the TypeScript compiler) becomes essential. It reads your TypeScript code, checks it for type errors, strips away all the type information, and outputs regular JavaScript that runtimes can execute.
The Workflow
- You write code in
.tsfiles - You run
tscto compile them - TypeScript generates
.jsfiles (in youroutDirif configured) - You run those
.jsfiles with Node or serve them to browsers
This compilation step isn't optional—it's the bridge between TypeScript's development-time features and JavaScript's runtime execution.
Key Takeaway: TypeScript is a development tool that must be compiled to JavaScript before execution—runtimes never see your type annotations, only the generated JavaScript code.