TypeScript

Intermediate · Roadmap · 64 lessons · 10 groups

The type system and the toolchain around it — everyday types, typing functions, structural typing, narrowing, generics, type-level programming, classes and decorators, modules and declaration files, and the practice of running TypeScript in a real codebase. The JavaScript language itself is taught in `javascript`; framework usage lives in `angular` and `react`. Sixty-four lessons.

0%

Not started

Nothing saved yet. Progress is kept in this browser until you sign in.

Start the path

Why TypeScript, and the toolchain · 6

Everyday types · 9

Typing functions · 5

Shaping data · 6

Narrowing · 6

Generics · 5

Type-level programming · 10

Classes and decorators · 3

Modules and declaration files · 5

TypeScript in practice · 9

01Why TypeScript, and what a type checker doesThe bugs plain JavaScript only reports at runtime, how a static type checker catches them early, and why every type disappears before your code runs.Beginner · 10 min02Installing TypeScript and your first compileInstall TypeScript per project, compile a file with tsc, read the emitted JavaScript, and use --init, --watch, and --noEmit.Beginner · 4 min03tsconfig explainedWhat the core tsconfig.json options control — target, lib, module, include, outDir, noEmit — and how to pick values for a real project.Beginner · 23 min04Strict mode and the compiler flags that matterWhat the strict flag turns on, the extra checks it leaves off like noUncheckedIndexedAccess, and which ones are worth enabling in a new project.Intermediate · 21 min05Running TypeScript without a build stepHow Node's built-in type stripping, erasableSyntaxOnly, tsx, and ts-node let you run .ts files directly, and what each one skips.Intermediate · 12 min06The editor and the TypeScript language serverHow the TypeScript language server powers hovers, quick fixes, and refactors in your editor, and what the Go-native TypeScript 7 compiler changes.Beginner · 29 min01Primitive typesThe seven primitive types TypeScript checks, why they are written lowercase, and what the compiler rejects once a value has one.Beginner · 6 min02Type annotations and type inferenceHow TypeScript works out most types from your values, where you still need to write an annotation, and why fewer annotations is usually better.Beginner · 8 min03Arrays and tuplesTyping lists of any length with `T[]`, and fixed-position data with tuples: named, optional, and rest elements, and why tuples need annotating.Beginner · 7 min04Object types, optional and readonly propertiesDescribing the shape of an object, marking properties that may be absent with `?`, and properties that must not be reassigned with `readonly`.Beginner · 10 min05Readonly and immutabilityRead-only arrays and tuples, `Readonly<T>`, and `as const`: how TypeScript stops mutation at compile time, and where that protection ends.Beginner · 5 min06any, unknown, never, and voidThe four special types: `any` switches checking off, `unknown` is the safe top type, `never` is the empty type, and `void` means no useful return.Beginner · 10 min07Null, undefined, and strict null checksHow `strictNullChecks` turns null and undefined into types you must handle, and how to model missing values with `T | null`, `?`, and `??`.Beginner · 3 min08Union and literal typesCombining types with `|`, using exact values like `"GET"` as types, and the widening rules that decide when TypeScript keeps a literal.Beginner · 10 min09Enums and their alternativesHow `enum` and `const enum` work, why they are not erasable syntax, and when an `as const` object with a derived union is the better choice.Intermediate · 9 min01Parameter and return typesWhy TypeScript needs you to annotate parameters but can usually work out return types itself, and when writing the return type anyway pays off.Beginner · 9 min02Optional, default, and rest parametersTyping parameters callers may leave out, parameters with fallback values, and functions that take any number of arguments.Beginner · 32 min03Function type expressions and call signaturesDescribing the type of a function itself, from the arrow syntax to call signatures for functions with properties and construct signatures for classes.Intermediate · 4 min04Function overloadsGiving one function several call signatures so its return type can follow its arguments, and knowing when a union or optional parameter is the simpler answer.Intermediate · 10 min05Typing this and callbacksDeclaring what `this` must be with a fake first parameter, and typing callbacks, including why a void callback type accepts a function that returns a value.Intermediate · 9 min01Type aliases vs interfacesTwo ways to name a type: what `type` can express that `interface` can't, where interfaces behave differently, and how to choose between them.Beginner · 10 min02Extending interfaces and intersection typesBuilding bigger types from smaller ones with `interface extends` and the `&` operator, how each handles conflicts, and why `extends` is cheaper.Intermediate · 5 min03Declaration mergingHow TypeScript combines declarations that share a name: interfaces, namespaces, functions, classes and enums, and why type aliases can't merge.Intermediate · 2 min04Structural typing and excess property checksTypeScript compares types by shape, not by name. Why that fits JavaScript, and the one place it gets stricter: extra properties on fresh object literals.Intermediate · 8 min05Index signatures and RecordTyping objects used as dictionaries: index signature syntax and its rules, what reading a missing key returns, and when `Record<K, V>` says it better.Beginner · 24 min06Type compatibility and varianceWhen one type can stand in for another: covariance, contravariance, why methods stay bivariant under strictFunctionTypes, and the in/out annotations.Advanced · 12 min01Control flow analysis and narrowingHow the checker follows if, return, and assignment to give a variable a narrower type on each line, using truthiness and equality checks.Beginner · 30 min02typeof, instanceof, and in narrowingWhat the type checker does with typeof, instanceof, and in checks, and where each one narrows less than you might expect.Beginner · 30 min03Discriminated unionsModelling data that comes in several shapes as a union of object types sharing a literal tag, so one check narrows the whole object.Intermediate · 5 min04Exhaustiveness checking with neverUsing the never type to make the compiler flag every switch that forgets a union member, including ones added long after the code was written.Intermediate · 10 min05Type guards and assertion functionsMoving narrowing checks into reusable functions with `x is T` predicates and `asserts` signatures, and what TypeScript 5.5 now infers for you.Intermediate · 5 min06Type assertions, non-null, and satisfiesOverriding the checker with `as` and `!` when you know more than it does, and checking a value with `satisfies` without losing its precise type.Intermediate · 21 min01Why generics, and generic functionsThe problem `any` and `unknown` can't solve, and how a type parameter lets one function keep the link between what goes in and what comes out.Intermediate · 13 min02Generic constraintsUsing `extends` to require a minimum shape from a type parameter, so a generic function can use that shape and still return the caller's exact type.Intermediate · 18 min03Generic defaults and const type parametersDefault type arguments that keep generic types short to use, and `const` type parameters that infer literal types without callers writing `as const`.Intermediate · 4 min04Generic interfaces, type aliases, and classesPutting type parameters on interfaces, type aliases, and classes, so reusable shapes like `Result<T>` and `Queue<T>` keep their contents typed.Intermediate · 6 min05How type argument inference worksHow TypeScript picks type arguments from a call's inference sites, why callbacks are inferred last, and how `NoInfer` stops an argument from widening `T`.Advanced · 26 min01The keyof and typeof type operatorsDeriving types from what already exists: keyof for a type's keys, type-level typeof for a value's type, and keyof typeof to get keys from a runtime object.Intermediate · 4 min02Indexed access typesLooking up a property's type with T[K]: nested lookups, unions of keys, T[keyof T], T[number] for arrays, and the typeof arr[number] pattern.Intermediate · 21 min03Utility types for objectsPartial, Required, Readonly, Pick, Omit and Record: deriving update payloads, public views and lookup tables from one model instead of copying it.Intermediate · 22 min04Utility types for unions and functionsExclude, Extract and NonNullable for filtering unions; ReturnType, Parameters and Awaited for reading function types; NoInfer for steering inference.Intermediate · 22 min05Mapped typesBuilding an object type by looping over keys: T[K] for property types, adding and removing readonly and ?, modifier preservation, and key remapping with as.Advanced · 10 min06Conditional typesChoosing between two types with `T extends U ? X : Y`, so a type can branch on its input the way an expression branches on a value.Advanced · 26 min07The infer keywordDeclaring a type variable inside a conditional's `extends` clause so TypeScript fills it in, to pull element, return and promise types out of other types.Advanced · 14 min08Distributive conditional typesWhy a conditional type applied to a union runs once per member, how `[T] extends [U]` turns that off, and why `never` in gives `never` out.Advanced · 8 min09Template literal typesBuilding string types with backtick syntax, generating unions from combinations, and pulling strings apart with `infer`.Advanced · 12 min10Recursive typesTypes that refer to themselves: JSON values and trees, deep transformations like DeepReadonly, the instantiation depth limit, and tail recursion.Advanced · 5 min01Classes and access modifiersWhat TypeScript adds to JavaScript classes: field declarations, public/private/protected, private vs #private, parameter properties, and override.Intermediate · 32 min02Abstract classes and implementing interfacesChecking a class against an interface with implements, sharing code through abstract classes, and how to choose between the two.Intermediate · 6 min03DecoratorsTypeScript 5's standard decorators, the (value, context) signature, field and accessor decorators, and how legacy experimentalDecorators differs.Advanced · 12 min01Modules and type-only importsHow TypeScript decides which imports survive compilation, and how import type, isolatedModules, and verbatimModuleSyntax make that explicit.Intermediate · 23 min02Module resolutionHow TypeScript finds the file behind an import under nodenext and bundler, why extensions and exports matter, and what paths does and doesn't do.Intermediate · 8 min03Namespaces: the legacy module systemWhy TypeScript has namespaces, what they compile to, why ES modules replaced them, and where they still appear in global declaration files.Intermediate · 34 min04Declaration files and DefinitelyTypedWhat .d.ts files are, where a package's types come from, how @types packages are found through types and typeRoots, and what skipLibCheck skips.Intermediate · 5 min05Writing declaration files and module augmentationTyping an untyped package with declare module, then extending a library's or the global scope's types with module augmentation and declare global.Intermediate · 10 min01Typing asynchronous codeHow TypeScript types promises and async functions: Promise<T>, Awaited<T>, Promise.all tuples, unknown in catch, and the floating promises tsc misses.Intermediate · 39 min02Branded types and nominal typingWhy two string IDs are interchangeable in TypeScript, and how a brand makes UserId and OrderId distinct types with no runtime cost.Advanced · 11 min03Validating untrusted data at runtimeTypes vanish at runtime, so API responses and form input need a real check. Schema libraries like Zod and Valibot validate data and infer the type.Intermediate · 17 min04Reading and debugging type errorsHow to read a long TypeScript error from the bottom up, inspect what the checker inferred, and corner a confusing error until it points at the real line.Intermediate · 5 min05Testing your typesRuntime tests can't see a wrong type. Type tests can: @ts-expect-error for code that must fail, expectTypeOf in Vitest or expect-type, and tsd.Advanced · 7 min06Linting with typescript-eslintSet up typescript-eslint with flat config and typed linting, and catch the async and any-related bugs that tsc lets through.Intermediate · 11 min07Migrating a JavaScript codebase to TypeScriptMove a JavaScript project to TypeScript gradually with allowJs, checkJs, JSDoc types, and strictness you tighten one file or one flag at a time.Intermediate · 19 min08Project references and monoreposSplit a large TypeScript repo into composite projects linked with references, build them with tsc --build, and know when workspace packages suffice.Advanced · 6 min09Publishing a typed libraryShip declaration files with your package, wire them up through package.json exports with types first, and check the result with Are the Types Wrong.Advanced · 21 min

Why TypeScript, and the toolchain

6 lessons

  1. 01 / 06Why TypeScript, and what a type checker doesThe bugs plain JavaScript only reports at runtime, how a static type checker catches them early, and why every type disappears before your code runs.10 min
  2. 02 / 06Installing TypeScript and your first compileInstall TypeScript per project, compile a file with tsc, read the emitted JavaScript, and use --init, --watch, and --noEmit.4 min
  3. 03 / 06tsconfig explainedWhat the core tsconfig.json options control — target, lib, module, include, outDir, noEmit — and how to pick values for a real project.23 min
  4. 04 / 06Strict mode and the compiler flags that matterWhat the strict flag turns on, the extra checks it leaves off like noUncheckedIndexedAccess, and which ones are worth enabling in a new project.21 min
  5. 05 / 06Running TypeScript without a build stepHow Node's built-in type stripping, erasableSyntaxOnly, tsx, and ts-node let you run .ts files directly, and what each one skips.12 min
  6. 06 / 06The editor and the TypeScript language serverHow the TypeScript language server powers hovers, quick fixes, and refactors in your editor, and what the Go-native TypeScript 7 compiler changes.29 min

Everyday types

9 lessons

  1. 01 / 09Primitive typesThe seven primitive types TypeScript checks, why they are written lowercase, and what the compiler rejects once a value has one.6 min
  2. 02 / 09Type annotations and type inferenceHow TypeScript works out most types from your values, where you still need to write an annotation, and why fewer annotations is usually better.8 min
  3. 03 / 09Arrays and tuplesTyping lists of any length with `T[]`, and fixed-position data with tuples: named, optional, and rest elements, and why tuples need annotating.7 min
  4. 04 / 09Object types, optional and readonly propertiesDescribing the shape of an object, marking properties that may be absent with `?`, and properties that must not be reassigned with `readonly`.10 min
  5. 05 / 09Readonly and immutabilityRead-only arrays and tuples, `Readonly<T>`, and `as const`: how TypeScript stops mutation at compile time, and where that protection ends.5 min
  6. 06 / 09any, unknown, never, and voidThe four special types: `any` switches checking off, `unknown` is the safe top type, `never` is the empty type, and `void` means no useful return.10 min
  7. 07 / 09Null, undefined, and strict null checksHow `strictNullChecks` turns null and undefined into types you must handle, and how to model missing values with `T | null`, `?`, and `??`.3 min
  8. 08 / 09Union and literal typesCombining types with `|`, using exact values like `"GET"` as types, and the widening rules that decide when TypeScript keeps a literal.10 min
  9. 09 / 09Enums and their alternativesHow `enum` and `const enum` work, why they are not erasable syntax, and when an `as const` object with a derived union is the better choice.9 min

Typing functions

5 lessons

  1. 01 / 05Parameter and return typesWhy TypeScript needs you to annotate parameters but can usually work out return types itself, and when writing the return type anyway pays off.9 min
  2. 02 / 05Optional, default, and rest parametersTyping parameters callers may leave out, parameters with fallback values, and functions that take any number of arguments.32 min
  3. 03 / 05Function type expressions and call signaturesDescribing the type of a function itself, from the arrow syntax to call signatures for functions with properties and construct signatures for classes.4 min
  4. 04 / 05Function overloadsGiving one function several call signatures so its return type can follow its arguments, and knowing when a union or optional parameter is the simpler answer.10 min
  5. 05 / 05Typing this and callbacksDeclaring what `this` must be with a fake first parameter, and typing callbacks, including why a void callback type accepts a function that returns a value.9 min

Shaping data

6 lessons

  1. 01 / 06Type aliases vs interfacesTwo ways to name a type: what `type` can express that `interface` can't, where interfaces behave differently, and how to choose between them.10 min
  2. 02 / 06Extending interfaces and intersection typesBuilding bigger types from smaller ones with `interface extends` and the `&` operator, how each handles conflicts, and why `extends` is cheaper.5 min
  3. 03 / 06Declaration mergingHow TypeScript combines declarations that share a name: interfaces, namespaces, functions, classes and enums, and why type aliases can't merge.2 min
  4. 04 / 06Structural typing and excess property checksTypeScript compares types by shape, not by name. Why that fits JavaScript, and the one place it gets stricter: extra properties on fresh object literals.8 min
  5. 05 / 06Index signatures and RecordTyping objects used as dictionaries: index signature syntax and its rules, what reading a missing key returns, and when `Record<K, V>` says it better.24 min
  6. 06 / 06Type compatibility and varianceWhen one type can stand in for another: covariance, contravariance, why methods stay bivariant under strictFunctionTypes, and the in/out annotations.12 min

Narrowing

6 lessons

  1. 01 / 06Control flow analysis and narrowingHow the checker follows if, return, and assignment to give a variable a narrower type on each line, using truthiness and equality checks.30 min
  2. 02 / 06typeof, instanceof, and in narrowingWhat the type checker does with typeof, instanceof, and in checks, and where each one narrows less than you might expect.30 min
  3. 03 / 06Discriminated unionsModelling data that comes in several shapes as a union of object types sharing a literal tag, so one check narrows the whole object.5 min
  4. 04 / 06Exhaustiveness checking with neverUsing the never type to make the compiler flag every switch that forgets a union member, including ones added long after the code was written.10 min
  5. 05 / 06Type guards and assertion functionsMoving narrowing checks into reusable functions with `x is T` predicates and `asserts` signatures, and what TypeScript 5.5 now infers for you.5 min
  6. 06 / 06Type assertions, non-null, and satisfiesOverriding the checker with `as` and `!` when you know more than it does, and checking a value with `satisfies` without losing its precise type.21 min

Generics

5 lessons

  1. 01 / 05Why generics, and generic functionsThe problem `any` and `unknown` can't solve, and how a type parameter lets one function keep the link between what goes in and what comes out.13 min
  2. 02 / 05Generic constraintsUsing `extends` to require a minimum shape from a type parameter, so a generic function can use that shape and still return the caller's exact type.18 min
  3. 03 / 05Generic defaults and const type parametersDefault type arguments that keep generic types short to use, and `const` type parameters that infer literal types without callers writing `as const`.4 min
  4. 04 / 05Generic interfaces, type aliases, and classesPutting type parameters on interfaces, type aliases, and classes, so reusable shapes like `Result<T>` and `Queue<T>` keep their contents typed.6 min
  5. 05 / 05How type argument inference worksHow TypeScript picks type arguments from a call's inference sites, why callbacks are inferred last, and how `NoInfer` stops an argument from widening `T`.26 min

Type-level programming

10 lessons

  1. 01 / 10The keyof and typeof type operatorsDeriving types from what already exists: keyof for a type's keys, type-level typeof for a value's type, and keyof typeof to get keys from a runtime object.4 min
  2. 02 / 10Indexed access typesLooking up a property's type with T[K]: nested lookups, unions of keys, T[keyof T], T[number] for arrays, and the typeof arr[number] pattern.21 min
  3. 03 / 10Utility types for objectsPartial, Required, Readonly, Pick, Omit and Record: deriving update payloads, public views and lookup tables from one model instead of copying it.22 min
  4. 04 / 10Utility types for unions and functionsExclude, Extract and NonNullable for filtering unions; ReturnType, Parameters and Awaited for reading function types; NoInfer for steering inference.22 min
  5. 05 / 10Mapped typesBuilding an object type by looping over keys: T[K] for property types, adding and removing readonly and ?, modifier preservation, and key remapping with as.10 min
  6. 06 / 10Conditional typesChoosing between two types with `T extends U ? X : Y`, so a type can branch on its input the way an expression branches on a value.26 min
  7. 07 / 10The infer keywordDeclaring a type variable inside a conditional's `extends` clause so TypeScript fills it in, to pull element, return and promise types out of other types.14 min
  8. 08 / 10Distributive conditional typesWhy a conditional type applied to a union runs once per member, how `[T] extends [U]` turns that off, and why `never` in gives `never` out.8 min
  9. 09 / 10Template literal typesBuilding string types with backtick syntax, generating unions from combinations, and pulling strings apart with `infer`.12 min
  10. 10 / 10Recursive typesTypes that refer to themselves: JSON values and trees, deep transformations like DeepReadonly, the instantiation depth limit, and tail recursion.5 min

Classes and decorators

3 lessons

  1. 01 / 03Classes and access modifiersWhat TypeScript adds to JavaScript classes: field declarations, public/private/protected, private vs #private, parameter properties, and override.32 min
  2. 02 / 03Abstract classes and implementing interfacesChecking a class against an interface with implements, sharing code through abstract classes, and how to choose between the two.6 min
  3. 03 / 03DecoratorsTypeScript 5's standard decorators, the (value, context) signature, field and accessor decorators, and how legacy experimentalDecorators differs.12 min

Modules and declaration files

5 lessons

  1. 01 / 05Modules and type-only importsHow TypeScript decides which imports survive compilation, and how import type, isolatedModules, and verbatimModuleSyntax make that explicit.23 min
  2. 02 / 05Module resolutionHow TypeScript finds the file behind an import under nodenext and bundler, why extensions and exports matter, and what paths does and doesn't do.8 min
  3. 03 / 05Namespaces: the legacy module systemWhy TypeScript has namespaces, what they compile to, why ES modules replaced them, and where they still appear in global declaration files.34 min
  4. 04 / 05Declaration files and DefinitelyTypedWhat .d.ts files are, where a package's types come from, how @types packages are found through types and typeRoots, and what skipLibCheck skips.5 min
  5. 05 / 05Writing declaration files and module augmentationTyping an untyped package with declare module, then extending a library's or the global scope's types with module augmentation and declare global.10 min

TypeScript in practice

9 lessons

  1. 01 / 09Typing asynchronous codeHow TypeScript types promises and async functions: Promise<T>, Awaited<T>, Promise.all tuples, unknown in catch, and the floating promises tsc misses.39 min
  2. 02 / 09Branded types and nominal typingWhy two string IDs are interchangeable in TypeScript, and how a brand makes UserId and OrderId distinct types with no runtime cost.11 min
  3. 03 / 09Validating untrusted data at runtimeTypes vanish at runtime, so API responses and form input need a real check. Schema libraries like Zod and Valibot validate data and infer the type.17 min
  4. 04 / 09Reading and debugging type errorsHow to read a long TypeScript error from the bottom up, inspect what the checker inferred, and corner a confusing error until it points at the real line.5 min
  5. 05 / 09Testing your typesRuntime tests can't see a wrong type. Type tests can: @ts-expect-error for code that must fail, expectTypeOf in Vitest or expect-type, and tsd.7 min
  6. 06 / 09Linting with typescript-eslintSet up typescript-eslint with flat config and typed linting, and catch the async and any-related bugs that tsc lets through.11 min
  7. 07 / 09Migrating a JavaScript codebase to TypeScriptMove a JavaScript project to TypeScript gradually with allowJs, checkJs, JSDoc types, and strictness you tighten one file or one flag at a time.19 min
  8. 08 / 09Project references and monoreposSplit a large TypeScript repo into composite projects linked with references, build them with tsc --build, and know when workspace packages suffice.6 min
  9. 09 / 09Publishing a typed libraryShip declaration files with your package, wire them up through package.json exports with types first, and check the result with Are the Types Wrong.21 min
Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark