TypeScript
Type system, generics, utility types, and TypeScript patterns asked in interviews.
Fundamentals
What is TypeScript & Why use it
TypeScript is JavaScript with a type system — catch bugs before they ship, get better autocomplete, refactor without fear.
Basic Types
string, number, boolean, null, undefined, any, unknown, never, void — the building blocks of every TS program.
Type Annotations vs Type Inference
When to write types explicitly and when to let TypeScript figure them out — the rule is simpler than you'd think.
Arrays, Tuples & Readonly Arrays
Three ways to type a list — when to use a flexible array, a fixed-length tuple, or an immutable readonly version.
Enums
Numeric, string, and const enums — what they emit at runtime, and why many teams skip them entirely.
Type vs Interface
The classic TypeScript interview question — when to reach for type, when for interface, and where they actually differ.
Type System Building Blocks
Union & Intersection Types
Union is OR (this or that), intersection is AND (both at once). Two operators that unlock most of TypeScript's expressiveness.
Literal Types & Const Assertions
Treat a specific value as its own type — and use 'as const' to lock things down. The backbone of safe APIs.
Type Aliases
Give any type a name. The simplest way to share, reuse, and compose types across a codebase.
Type Narrowing & Type Guards
How TypeScript figures out the exact type inside an if-branch — typeof, instanceof, in, and user-defined predicates.
Discriminated Unions
The cleanest way to model 'this OR that' shapes — a shared literal tag lets TypeScript narrow each branch exactly.
Functions
Function Types & Signatures
How we describe the shape of a function in TypeScript — parameter types, return types, and call signatures.
Optional, Default & Rest Parameters
Three ways to make function parameters flexible — skip them, default them, or collect them.
Function Overloading
Declare multiple signatures for one function so the same name can be called with different argument shapes.
Objects & Classes
Interfaces
Describe object shapes with interfaces — extend, optional, readonly, and index signatures.
Classes & Access Modifiers
Control what's visible where with public, private, protected, and readonly.
Abstract Classes & Implementing Interfaces
Abstract classes can't be instantiated directly — they define a template that subclasses must complete.
Static Members & Parameter Properties
Static members belong to the class itself; parameter properties cut constructor boilerplate.
Generics
Generic Functions & Type Parameters
Generics let one function work with many types while keeping full type safety — the cornerstone of reusable TS code.
Generic Constraints (extends)
Use `extends` to restrict what types a generic can accept — getting flexibility without giving up safety.
Generic Classes & Interfaces
Parameterize entire data structures with types — the backbone of typed collections, repos, and stores.
Advanced Types
keyof, typeof & Indexed Access Types
Three operators that let us reach into existing types and pull out keys, value shapes, or property types — the foundation of every advanced TS trick.
Mapped Types
A way to build new types by walking over the keys of an existing one and transforming each property — the engine behind Partial, Readonly, and friends.
Conditional Types & infer
If-else at the type level. The mechanism behind ReturnType, Awaited, and most clever library types we use every day.
Template Literal Types
String template literals — but at the type level. Lets us build, split, and pattern-match string types with full type safety.
Utility Types
The standard-library helpers — Partial, Pick, Omit, Record, ReturnType, Awaited and friends. The ones we reach for daily.
Type Assertions (as) vs satisfies
Two ways to tell TS something about a value — one forces the type, the other only validates it. Picking the wrong one silently breaks our types.
Tooling & Config
Modules (import/export) & Namespaces
How TypeScript organizes code — ES modules are the modern way, namespaces are the legacy alternative we still see in old code.
tsconfig.json Essentials
The handful of compiler flags that actually matter — strict, target, moduleResolution, paths — and what each one really does.
Declaration Files (.d.ts)
Files that describe the shape of JavaScript code to TypeScript — how we type third-party JS libs, globals, and asset imports.
Patterns & Best Practices
Decorators
Functions that modify classes, methods, or properties. Two flavors exist — the experimental legacy form and the new TC39 stage 3 standard.
Common TypeScript Pitfalls & Best Practices
any vs unknown, branded types, exhaustiveness checks, structural typing surprises — the traps that bite us in real code.