TypeScript Interview Questions
18 TypeScript interview questions with worked answers, complexity notes, and runnable code you can edit in the browser — ordered easy to hard so you build up steadily. Free, no signup. Open any question for the full answer.
Modeling intent so bugs fail at compile time
TypeScript interviews are not about memorizing utility types — they are about judgment. The good use of the type system encodes what your code actually means, so a whole class of mistakes becomes unrepresentable and fails at compile time instead of in production. The bad use over-types everything, fights the compiler, and produces generics so clever nobody can change them. Interviewers are listening for where you draw that line.
Start with the everyday tools and know exactly when each earns its place. Generics let a function preserve the relationship between its input and output types rather than throwing that information away with any. Discriminated unions model a value that is one of several shapes — a request that is loading, loaded, or errored — and give you exhaustive checking so adding a new state surfaces every place that must handle it. Narrowing is how you earn access to a value’s specific type through control flow, type guards, and in checks.
The utility types — Partial, Pick, Omit, Record, ReturnType — are shortcuts for transformations you would otherwise write by hand, and knowing them signals fluency. But the deeper signal is knowing when not to reach for the type system at all: when a simpler type is clearer, when inference already has it covered, and when a runtime check is the honest tool because the data crosses a boundary the compiler cannot see. These questions move from the foundations into that harder territory of type-level modeling and restraint.
Easy
- type vs interface — when to use which? Types vs Interfaces
What's the difference between `type` and `interface`? When do you reach for each? - Why generics? identity + a constrained generic Generics
Explain generics with a concrete example. Then constrain a generic so it only accepts objects with an `id`. - unknown vs any vs never Top & Bottom Types
Explain the difference between unknown, any, and never, and when to use each. - Structural typing & excess-property checks Structural Typing
TypeScript uses structural typing, not nominal. What does that mean — and why does an object literal with an extra field error when a… - Type assertions: as, !, and why they're unsafe Type Assertions
Explain type assertions (`as T`), the non-null assertion (`!`), and `as unknown as T`. Why are they escape hatches rather than conversions? - Tuples, readonly arrays, and named elements Tuples & Readonly Arrays
How do you type a fixed-length tuple vs an array? Show named tuple members, a rest element, and `readonly` arrays — and why readonly…
Medium
- Partial, Pick, Omit, Record — and when Utility Types
Explain Partial, Required, Pick, Omit, and Record with a use case for each. - Model state with a discriminated union Discriminated Unions
Model an async request's state so impossible states are unrepresentable, and TS narrows correctly. - Type guards & narrowing Narrowing
How does TS narrow types? Write a user-defined type guard, and show exhaustiveness with never. - as const and literal types vs enum Literal Types
What does `as const` do, and when would you prefer a literal union over a TypeScript enum? - Function overloads vs generics vs unions Function Signatures
When should you use function overloads, and when is a generic or a union parameter the better tool? - The satisfies operator satisfies Operator
What problem does `satisfies` solve that neither a type annotation nor `as` does? Show a config object where it matters. - keyof, typeof, and indexed access types keyof, typeof & Indexed Access
Explain `keyof`, the `typeof` type operator, and indexed access types. Use them to write a fully type-safe property getter.
Hard
- Write your own mapped + conditional type Mapped & Conditional Types
Implement DeepReadonly and explain mapped types, keyof, and conditional types. - Template literal types Template Literal Types
What are template literal types? Build an event-handler name type from a union of events, and show inferring a piece back out of a string… - Variance & function parameter bivariance Variance
Explain covariance and contravariance for function types. Why are method parameters bivariant in TypeScript, and what does… - Branded (nominal) types over a structural system Branded Types
TypeScript is structural, so `UserId` and `OrderId` (both `string`) are interchangeable. How do you make them incompatible — and what's the… - Recursive types & type-safe object paths Recursive Types
Write a recursive type. Then build a `Paths ` that produces the dotted key paths of a nested object, and a `Get ` that returns the type at…
Other topics
HTML/CSS · Browser · JavaScript · React · System Design · Accessibility · Web Performance · Testing · Networking/Security · DSA