Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

TS
TypeScript
0/10 completed
Beginner
Why TypeScript?Basic types and inferenceTyping functionsObjects, interfaces and type aliases
Intermediate
Unions and narrowingLiteral types, tuples and enumsGenerics
Advanced
Utility typesMapped and conditional types
Pro
TypeScript in real projects
Tracks / TypeScript / Beginner

Why TypeScript?

TypeScript is JavaScript with types. You write JavaScript plus a few annotations that describe what kind of data your variables, functions and objects hold. The TypeScript compiler checks those types before your code runs, then strips them away to produce plain JavaScript.

It was created by Microsoft in 2012, and today it's the default choice for professional JavaScript: React, Next.js, Angular, Vue, Node.js backends and most large codebases.

The problem TypeScript solves

JavaScript happily runs code that's obviously wrong, and you only find out when a user hits the bug:

JavaScript · editable

The same code in TypeScript. Press Run. The real TypeScript compiler checks it in your browser:

TypeScript · editable

TypeScript catches all three bugs and tells you exactly where they are. In a real editor like VS Code, you'd see red squiggly underlines as you type, before you even save.

The first run downloads the TypeScript compiler (about 3 MB). After that, checks are nearly instant.

Types disappear at runtime

TypeScript is a development tool. Browsers and Node.js run JavaScript, so the compiler removes all types. Open "View the compiled JavaScript" under the output of this example:

TypeScript · editable

The compiled output is just ordinary JavaScript: no interface, no : string. That's why TypeScript has zero runtime cost.

What you get

Benefit Why it matters
Catch bugs early Typos, wrong arguments and missing properties are found in the editor, not in production
Autocomplete The editor knows every property and method, so you type less and guess less
Fearless refactoring Rename a property and the compiler shows every place that needs updating
Self-documenting code Function signatures show what goes in and what comes out
Teamwork at scale Types are a contract between modules and developers

Studies of open-source bugs have found that a meaningful share (around 15% in one well-known study) could have been caught by a type checker.

Is it hard to learn?

No. All JavaScript is valid TypeScript (with type errors at worst). You can start by adding types to one function at a time. TypeScript also infers most types automatically, so you often write fewer annotations than you'd expect.

Using TypeScript for real

bash
npm install --save-dev typescript   # add it to a project
npx tsc --init                      # create tsconfig.json
npx tsc                             # type-check and compile .ts → .js

Most modern tools support TypeScript out of the box: Vite (npm create vite@latest, then choose a TS template), Next.js, Deno, Bun, and recent Node.js versions, which can run .ts files directly by stripping the types.

Practice

Fix the type errors so this program compiles with ✓ No type errors:

TypeScript · editable
✎ Check your understanding

1.When does TypeScript check your types?

2.What does the browser actually run?