TypeScript study guide
A reference for interviews, not a tutorial. 51 topics from the basics up, each one explaining the mechanism with runnable examples and ending with questions from the same bank the quizzes draw from.
Basic
13 of 13 written · 66 quiz questions →
Annotations, inference, the primitive types, and the difference between `any` and `unknown`.
- What TypeScript is7 minA compile-time layer over JavaScript — what the compiler checks, what it erases, and the class of bug it cannot catch.Type annotations
- Annotations and inference12 minWhere to write a type and where to let the compiler work it out, why `let` widens and `const` does not, and what contextual typing gives you for free.Type annotationsType inference
- Primitive types11 minThe lower-case types you should actually use, what `strictNullChecks` changes about all of them, and the `object` type you probably do not want.Primitives
- Arrays and tuples12 minTwo spellings of the array type, what a tuple adds, and the two holes — index access and `push` — where the compiler stops protecting you.ArraysTuples
- Objects and interfaces15 minDescribing the shape of an object, what optional and `readonly` really promise, and the excess property check that only fires on a literal.ObjectsInterfaces
- Type aliases12 minA name for any type at all — not just object shapes — and the two things that genuinely separate an alias from an interface.Type aliases
- Unions and intersections13 minWhy a union gives you a smaller surface and an intersection a larger one, and why that is the opposite of what "or" and "and" suggest.Unions and intersections
- Literal types and as const13 minA single value as a type, why `let` and object properties lose it, and the `as const` pattern that derives a union from real data.Literal types
- Typing functions15 minThree ways to name a function type, what optional and default parameters really differ on, and why a `void` return accepts anything.Functions
- Enums12 minThe one TypeScript construct that emits JavaScript, the reverse mapping, the numeric soundness hole, and why a literal union usually wins.Enums
- any, unknown, never and void13 minThe four special types, where each sits in the assignability hierarchy, and why `any` is contagious in a way `unknown` is not.Type annotations
- Structural typing12 minCompatibility decided by shape rather than by name — what that buys you, where the compiler makes an exception, and how to fake a nominal type.Structural typing
- tsconfig and strict14 minThe handful of compiler options that actually change how you write code, what `strict` turns on, and why `tsc --noEmit` is the command most projects run.tsconfig
Intermediate
16 of 16 written · 66 quiz questions →
Narrowing, type guards, generics and the utility types — where a mid-level interview lives.
- type versus interface12 minThe two differences that are real — merging, and what each can name — and a rule for the cases where it genuinely does not matter.Type aliasesInterfaces
- Declaration merging13 minTwo declarations of one name combining into a single type — the rule, the limits, and the one thing it is genuinely for.Interfaces
- Narrowing15 minHow the compiler follows your checks to work out what a value is, which checks it understands, and the two places the narrowing is quietly lost.Narrowing
- Type guards and predicates14 minTeaching the compiler a check it cannot work out for itself — the `value is T` predicate, assertion signatures, and why a wrong guard is as dangerous as a cast.Type guards
- Discriminated unions16 minThe single most useful pattern in TypeScript — one literal property that lets the compiler tell the branches apart, and makes impossible states impossible.Discriminated unions
- Type assertions12 minOverruling the compiler with `as` and `!` — what they emit, the one rule that constrains them, and why a guard is almost always the better tool.Type assertions
- The satisfies operator10 minCheck a value against a type without losing what the compiler inferred — the operator that makes most uses of `as` on a literal unnecessary.satisfies
- keyof and indexed access14 minReading keys and property types out of a type instead of writing them again — the two operators every utility type is built from.keyof
- Generics13 minA type parameter is a relationship between types — what that buys over `any`, how inference fills it in, and the rule for when a generic is worth writing.Generics
- Generic constraints13 minWhat `extends` promises the function body, why it means "at least" rather than "exactly", and the `K extends keyof T` pattern you will write constantly.Generic constraints
- Generic interfaces and classes14 minPutting the type parameter on the container rather than the function — the envelope pattern, binding a parameter at implementation time, and generic classes.Generics
- Classes and access modifiers16 minWhat TypeScript adds to a JavaScript class — modifiers that vanish at compile time, parameter properties, `abstract`, and the field-initialisation check.Access modifiers
- implements and extends15 minOne inherits code and one only checks a shape — what each costs, why a class can implement many interfaces, and what `implements` does not do.Classes
- Utility types14 minThe built-in type transformations worth knowing by heart, why every one of them is shallow, and the whitelist-versus-blacklist choice between `Pick` and `Omit`.Utility types
- Assignability and excess properties14 minThe rule that decides whether one type fits where another is expected, the literal-only check layered on top, and the weak-type rule that catches the rest.Structural typing
- Modules and import type12 minWhy a file with no import or export is global, what `import type` guarantees about the emit, and the alias that type-checks and then fails at runtime.Modules
Advanced
12 of 12 written · 68 quiz questions →
Conditional and mapped types, `infer`, decorators, variance and the compiler itself.
- Conditional types14 minAn if-statement for types — how `extends` is read as a question, why a union distributes across it, and the idioms that turn that into real work.Conditional types
- The infer keyword13 minPattern matching for types — how `infer` names a piece of a shape you matched, where multiple candidates come from, and how it is used to write `ReturnType` from scratch.infer
- Mapped types16 minA loop over the keys of a type — the four modifiers you can add or remove, how `as` renames a key, and the clause that filters keys out entirely.Mapped types
- Template literal types15 minString interpolation in the type system — how a union inside a template multiplies out, the four intrinsic case utilities, and parsing a string with `infer`.Template literal types
- Type-level programming13 minConditionals, mapped types, `infer` and recursion combined into real computation — and the judgement about when a clever type costs more than it pays.Conditional typesMapped types
- Deriving types from types15 minSingle source of truth in the type system — `typeof`, `as const`, indexed access and schema inference, so a shape is declared once and everything else follows.Utility types
- Generics, deeper17 minHow the compiler actually resolves a type parameter — inference sites, constraints, defaults, variance annotations, and the generic signatures that make a library usable.GenericsGeneric constraints
- Decorators18 minTwo incompatible decorator systems, what each one receives, and why the version in most tutorials needs a compiler flag the standard one does not.Decorators
- Declaration files15 minWhat a `.d.ts` is for, how `declare` differs from a definition, and the three ways to add types to a library that has none.Declaration files
- Variance15 minWhich way a type parameter is allowed to move — covariance, contravariance, bivariance and invariance, where TypeScript is deliberately unsound, and how to read the resulting errors.VarianceStructural typing
- Typing async code and errors17 minWhat `Promise<T>` and `Awaited<T>` actually guarantee, why a `catch` parameter is `unknown`, and how to type a result you are forced to handle.async / awaitError handling
- The compiler and the build13 minWhat `tsc` does and does not do in a modern toolchain, the options that change program meaning rather than output, and why type-checking and transpiling are now separate jobs.tsconfigTooling
Patterns & principles
10 of 10 written · 24 quiz questions →
The same patterns a senior interview asks about, written the way TypeScript expresses them — with the interfaces, generics and abstract classes JavaScript has to imitate.
- The Module pattern13 minEncapsulation in TypeScript — an ES module with a declared public interface, why `namespace` is the obsolete version of the same idea, and where `#private` fits.Design patterns
- The Factory pattern15 minA function that decides what to build — and in TypeScript, one that can return a different type depending on what it was asked for.Design patterns
- The Singleton pattern15 minOne instance, and the four ways TypeScript spells it — plus the honest case that the pattern is usually the wrong answer and injection is the right one.Design patterns
- Observer and Pub/Sub12 minA typed event emitter — one event map, and every `emit` and `on` call checked against it, payload included.Design patterns
- The Strategy pattern15 minInterchangeable algorithms with a contract the compiler enforces — a `Record` over a literal union that makes a missing strategy a build error rather than an `undefined`.Design patterns
- The Builder pattern15 minStep-by-step construction where the type changes as you go — so `build()` does not exist until the required pieces have actually been supplied.Design patterns
- The Repository pattern16 minA collection-shaped interface over storage — and in TypeScript a generic contract the compiler checks, with the entity's id type as a parameter rather than an assumption.Design patterns
- The Decorator pattern16 minWrapping an object to add behaviour without changing it — and why this has almost nothing to do with TypeScript's `@decorator` syntax.Design patterns
- DRY, KISS and YAGNI15 minThree principles read through the type system — what DRY means for types, why a clever type is usually the wrong answer, and the generic nobody needed.PrinciplesGood practice
- SOLID in TypeScript21 minThe five principles where the compiler can actually check them — Liskov as variance, Interface Segregation as literally interfaces, and Dependency Inversion as a constructor parameter.Principles