BeCuriouzBeCuriouz

Learn something new every day

🔷 TypeScript
⚙️

Meet tsc: How TypeScript Becomes JavaScript

💡 tsc type-checks and transpiles your .ts into .js using rules from tsconfig.json, and turning on strict is what makes TypeScript actually catch bugs.

Browsers and Node.js don't understand TypeScript — they run JavaScript. So before your code executes, the TypeScript compiler (tsc) does two jobs: it type-checks your code (catching the errors you saw in earlier cards) and it transpiles the .ts files into plain .js. A file like app.ts becomes app.js with the type annotations stripped away.

You control all of this with a tsconfig.json file at the root of your project. Running tsc --init creates one with sensible defaults. It tells the compiler which files to include, which JavaScript version to output (target), and dozens of other options:

json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "strict": true,
    "outDir": "dist"
  }
}

The single most important setting is strict. Turning it on enables a bundle of stricter checks at once — most notably strictNullChecks (so null and undefined can't sneak into a value that isn't supposed to hold them) and noImplicitAny (so a value never silently becomes the escape-hatch any type). Without strict, TypeScript quietly lets many bugs through and gives you little more than fancy autocomplete.

A key thing to remember: types are erased at compile time. They guide tsc while it checks your code, but they vanish from the output — there's zero runtime cost and no type information left to inspect while your program runs.

⚙️ Meet tsc: How TypeScript Becomes JavaScript — BeCuriouz