Learn core TypeScript in ~4 weeks the way you actually get good at it: by writing code. 20 hands-on, test-driven blocks under strict mode, each with runnable examples and verified reference solutions.
A complete, free course for JavaScript developers learning TypeScript. You don't
read about types — you implement functions, make failing tests pass, and satisfy the
compiler under strict. Perfect for self-study, a study group, or a workshop syllabus.
- 🧪 Test-driven — every block ships failing tests; you make them green. No passive reading.
- 🔒 Strict from day one —
strict,noUncheckedIndexedAccess,noUnusedParameters, and more, so you learn the habits real codebases expect. - ✅ Verified solutions — every reference answer is itself tested (
npm run test:solutions), so what you compare against is guaranteed correct. - 🧠 Type-level tests — exercises about types are checked with
expectTypeOf, not just runtime asserts. - 📦 Real-world finish — modules, async, the
Result<T, E>pattern, declaration files, and a multi-module capstone library.
This is a GitHub template repository — click Use this template to get your own copy you can commit solutions to and track progress with git. (Or just fork it.)
# 1. Create your copy (Use this template) or clone
git clone https://github.com/Rossoline/typescript-learn.git
cd typescript-learn
# 2. Install dependencies (Node.js 18+)
npm install
# 3. Run all tests — most fail until you solve the exercises
npm test
# 4. Work one block at a time, re-running on save
npx vitest blocks/01-getting-started- Read the block's
README.md. - Open
src/examples.ts, read it, and run it to see the output:npx tsx blocks/01-getting-started/src/examples.ts
- Open
src/exercises.tsand implement each// TODO. - Run that block's tests until they all pass:
npx vitest blocks/01-getting-started
- Check your types are clean, then compare with
solutions/:npm run typecheck
Type-only blocks (14 & 18): there the exercise is to write types (mapped/ conditional types, a
.d.ts), so the type checker is the test — runnpm run typecheckand make the errors in that block disappear.
blocks/NN-topic/
├── README.md # the topic explained, with examples and the exercise list
├── src/examples.ts # runnable, worked examples
├── src/exercises.ts # practice tasks with // TODO stubs — your job
├── tests/ # automated tests (Vitest) — make them pass
└── solutions/ # reference solutions (try the exercises first!)
The full day-by-day plan is in PLAN.md. Twenty blocks across four weeks:
| Week | Theme | Blocks |
|---|---|---|
| 1 | Foundations | 01 Getting Started · 02 Basic Types · 03 Functions · 04 Objects & Type Aliases · 05 Union & Literal Types |
| 2 | Shaping Types | 06 Interfaces · 07 Classes · 08 Enums · 09 Narrowing · 10 Type Assertions |
| 3 | Advanced Core | 11 Generics · 12 Utility Types · 13 keyof / typeof / Indexed Access · 14 Mapped & Conditional Types · 15 Modules |
| 4 | Practical TS | 16 Async & Promises · 17 Error Handling & Result Types · 18 Declaration Files & @types · 19 tsconfig & strict mode · 20 Capstone Project |
| Command | What it does |
|---|---|
npm test |
Run every block's tests (your progress). |
npm run typecheck |
Type-check the whole project (tsc --noEmit). |
npm run test:solutions |
Verify the reference solutions all pass. |
npx vitest blocks/NN-... |
Run/watch a single block. |
npx tsx <file> |
Run any .ts file directly. |
Works out of the box in VS Code (install the Vitest extension for inline test
running) and WebStorm / IntelliJ (right-click a *.test.ts → Run 'Vitest'; enable
Toggle auto-test to re-run on save). TypeScript errors show inline as you type in both.
Each exercise file exports functions or values; the matching test imports them and
asserts behavior. Implement a // TODO correctly and its test goes green. The goal
isn't only passing tests — it's writing code the compiler accepts under strict.
- Use this template (or fork) so you can commit your solutions and build a streak.
- Commit after each block (
git commit -m "block 03 done"). - Don't skip the READMEs — the exercises assume you read them.
- Stuck for ~15 min? Read the solution, understand it, then re-implement from memory.
If this helped you learn TypeScript, please ⭐ the repo — it helps others find it. Contributions and issue reports are welcome. Happy typing! 🧠