10 role-specific questions
TypeScript Developer Interview Questions & Answers
TypeScript interviews look for people who use the type system to prevent bugs rather than fight it: generics, narrowing, utility types, strictness, and knowing where types end and runtime validation begins.
Free, no sign-up. 100 questions in this role's practice pool, including behavioural, HR and situational questions.
TypeScript interview questions
Generics, narrowing, utility types and type design — what TypeScript interviews actually test.
1.
Explain generics in TypeScript with an example.
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Whether you can write reusable, type-safe code rather than reaching for `any`.
Key points a strong answer covers
- Type parameters. Generics are type parameters — placeholders filled in when the function or type is used.
- Preserve the relationship. They keep the link between input and output types, e.g.
first<T>(arr: T[]): T. - Constraints.
<T extends { id: string }>restricts what T can be. - Instead of any. Unlike
any, generics keep checking and autocomplete.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Using generics where a plain union would do.
- Over-constraining so callers fight the types.
Likely follow-up questions
- How would you type a function
getProperty(obj, key)? - What does a default type parameter do?
Example strong answer
Generics are type parameters: placeholders that the caller fills in, so one function or type works for many types without losing safety. For example,
function first<T>(items: T[]): T | undefinedreturns aUserwhen givenUser[]— the relationship between input and output is preserved, whichanywould throw away. Constraints narrow what's allowed:function byId<T extends { id: string }>(items: T[], id: string)works for anything with an id. A common real use is a typed API helper,fetchJson<T>(url): Promise<T>, orgetProperty<T, K extends keyof T>(obj: T, key: K): T[K].2.
What's the difference between
interfaceandtype?BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Practical judgement about everyday type declarations.
Key points a strong answer covers
- Both describe object shapes. For object shapes they're largely interchangeable.
- Declaration merging. Interfaces can be re-declared and merge; type aliases can't.
- Types do more. Type aliases can name unions, tuples, primitives, mapped and conditional types.
- Extending. Interfaces use
extends; types combine with&.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Claiming one is always faster or always better.
- Not knowing that only types can express unions.
Likely follow-up questions
- When is declaration merging useful?
- How would you extend a third-party library's type?
Example strong answer
For describing an object's shape they're nearly interchangeable. The differences: an interface can be declared again and the declarations merge, which is how you augment a library's types — for example adding a field to Express's
Request. A type alias can name anything: unions like'idle' | 'loading', tuples, primitives, and mapped or conditional types, which interfaces can't express. Interfaces extend withextends; types combine with intersections (&). My rule is to follow the codebase's convention — often interfaces for public object contracts and types for unions and computed types.3.
What is type narrowing? Show a few ways to narrow a union.
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Ability to work safely with unions and unknown data.
Key points a strong answer covers
- Definition. TypeScript refines a union to a more specific type inside a branch, based on control flow.
- typeof / instanceof / in.
typeof,instanceofand theinoperator narrow types. - Discriminated unions. A shared literal field (
kind) lets a switch narrow each case. - Type guards / exhaustiveness. Custom guards (
x is User) and anevercheck for exhaustive switches.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Casting with
asinstead of narrowing. - Forgetting the exhaustive
nevercheck when a new case is added.
Likely follow-up questions
- What does
value is Usermean in a return type? - How does an exhaustive switch catch missing cases at compile time?
Example strong answer
Narrowing is TypeScript refining a broad type to a specific one inside a branch, based on the checks you write.
typeof x === 'string'narrows primitives,instanceof Datenarrows classes, and'email' in contactnarrows object unions. My favourite pattern is a discriminated union:type State = { status: 'loading' } | { status: 'error'; error: string } | { status: 'done'; data: Item[] }— switching onstatusgives exact types per case, and adefaultbranch assigning tonevermakes the compiler flag any case I forget. For external data I write type guards likefunction isUser(x: unknown): x is User.4.
Which TypeScript utility types do you use, and for what?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Fluency with the standard type toolbox.
Key points a strong answer covers
- Partial / Required.
Partial<T>makes all fields optional (e.g. update payloads);Required<T>the opposite. - Pick / Omit.
PickandOmitderive a type with a subset of keys. - Record.
Record<K, V>types dictionaries and lookup maps. - Return / Parameters / Awaited.
ReturnType,Parameters,Awaited,Readonly,Excludederive types from others.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Duplicating types by hand instead of deriving them.
- Listing utility types without saying when you'd use them.
Likely follow-up questions
- How is
Omitbuilt from other types? - How would you make a deep partial type?
Example strong answer
I use them to derive types instead of duplicating them.
Partial<User>types an update payload where every field is optional.Pick<User, 'id' | 'name'>andOmit<User, 'password'>give a safe public view.Record<Role, Permission[]>types a lookup table and makes sure every role is covered.ReturnType<typeof createStore>andAwaited<ReturnType<typeof fetchUser>>let the implementation be the source of truth.Readonlydocuments data that mustn't change, andExclude<Status, 'deleted'>trims a union. The benefit is that when the base type changes, every derived type follows.- Partial / Required.
5.
What's the difference between
any,unknownandnever?BeginnerTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Type safety discipline.
Key points a strong answer covers
- any turns off checking.
anydisables type checking for that value. - unknown must be narrowed.
unknownaccepts anything but must be narrowed before use. - never is impossible.
neveris the type with no values — unreachable code, functions that always throw, exhaustive checks. - When to use. Use
unknownfor external data and catch variables.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Using
anyfor API responses. - Not knowing where
neveris useful.
Likely follow-up questions
- Why is a
catch (e)variableunknownwith strict settings? - How would you validate an
unknownAPI response at runtime?
Example strong answer
anyswitches type checking off — you can do anything with it, so errors slip through and spread.unknownalso accepts any value, but you can't use it until you narrow it with a check or a type guard, so it's the safe choice for JSON from an API, user input or a caught error.neveris the opposite end: a type with no possible values. It's the return type of a function that always throws, and the type left in an exhaustive switch, so assigning tonevermakes the compiler catch unhandled cases. For API data I'd combineunknownwith a runtime validator like Zod.- any turns off checking.
6.
What does
strictmode in tsconfig change, and would you enable it on an existing project?IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Experience running TypeScript in real codebases.
Key points a strong answer covers
- strictNullChecks. null and undefined are no longer assignable to every type.
- noImplicitAny. Untyped parameters become errors instead of silently
any. - Other flags. It bundles several checks: function types, property initialisation, unknown in catch.
- Incremental migration. On an existing project, enable flags one at a time or per folder, fixing errors gradually.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Suggesting turning it on in one go in a huge codebase with no plan.
- Not knowing strictNullChecks is the most valuable part.
Likely follow-up questions
- What's the difference between
?.and!? - How would you stop new errors while migrating?
Example strong answer
strictturns on a family of checks. The most valuable isstrictNullChecks:nullandundefinedare no longer silently allowed everywhere, which catches a whole class of runtime crashes.noImplicitAnymakes untyped parameters errors, and others check function parameter types, class property initialisation and make catch variablesunknown. Yes, I'd enable it on an existing project, but gradually: turn on one flag at a time, fix the errors folder by folder, and use// @ts-expect-errorwith a ticket only where needed, while CI prevents new violations.7.
Explain mapped and conditional types, with a real use case.
AdvancedTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Advanced type-level programming for library or shared-code work.
Key points a strong answer covers
- Mapped types. Mapped types build a new type by iterating over keys:
{ [K in keyof T]: ... }. - Conditional types.
T extends U ? X : Ychooses a type based on another. - infer.
inferextracts a type inside a conditional, e.g. a promise's value. - Real use case. E.g. a form-errors type with the same keys as the form values.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Writing clever types that nobody on the team can read.
- No practical example.
Likely follow-up questions
- How is
ReturnTypeimplemented? - What is a distributive conditional type?
Example strong answer
A mapped type iterates over the keys of another type to build a new one:
type FormErrors<T> = { [K in keyof T]?: string }gives a form's error object exactly the same keys as its values, so adding a field updates both. A conditional type picks a type based on a condition:T extends string ? 'text' : 'other'. Withinferyou can extract parts —type Unwrap<T> = T extends Promise<infer V> ? V : Tis essentially howAwaitedworks, andReturnTypeuses the same trick. I use these in shared code like typed event emitters, but keep them commented and tested, because readability matters more than cleverness.- Mapped types. Mapped types build a new type by iterating over keys:
8.
Should you use enums in TypeScript? What are the alternatives?
IntermediateTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Awareness of runtime cost and trade-offs.
Key points a strong answer covers
- Enums emit code. Regular enums generate a runtime object (and numeric enums a reverse mapping).
- Union of literals. A union of string literals is often simpler and erases completely.
- as const objects. An
as constobject gives runtime values plus a derived union type. - Trade-offs. Numeric enums accept any number; const enums have tooling issues with isolated modules.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Not knowing enums exist at runtime.
- Treating the choice as purely stylistic.
Likely follow-up questions
- How do you get a union type from an
as constobject? - Why might a build tool reject const enums?
Example strong answer
Enums work, but they're one of the few TypeScript features that emit runtime code, and numeric enums are loose — any number is assignable. Most of the time I use a union of string literals, like
type Status = 'draft' | 'published', which erases completely and reads clearly. When I also need the values at runtime — for a dropdown, say — I use an object withas constand derive the type withtypeof STATUS[keyof typeof STATUS].const enumavoids the runtime object but doesn't play well with isolated-module compilers like esbuild or SWC. So: unions by default,as constobjects when I need values, enums if the codebase already standardises on them.9.
TypeScript types disappear at runtime. How do you make sure API data really matches your types?
AdvancedTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Understanding the boundary between compile-time and runtime safety.
Key points a strong answer covers
- Types are erased. Types are erased when compiled, so they can't check data that arrives at runtime.
- Validate at the boundary. Validate external data where it enters the app (API responses, forms, env vars).
- Schema libraries. Libraries like Zod define a schema once and infer the type from it.
- Handle failures. Decide what to do when validation fails: log, show an error, or fall back.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Using
as Useron a fetch response and calling it type-safe. - Validating deep inside the app instead of at the boundary.
Likely follow-up questions
- How would you keep server and client types in sync?
- What's the cost of validating every response?
Example strong answer
Type annotations are erased at compile time, so
const user = await res.json() as Useris just a promise to the compiler — nothing checks it. I validate at the boundary, where data enters the app: API responses, form input, URL params and environment variables. I use a schema library such as Zod: define the schema once, infer the TypeScript type from it withz.infer, and callsafeParseon the data, so the type and the check can't drift apart. When parsing fails I log the details and show a clear error rather than letting undefined values crash something three screens later. Where possible I also generate client types from the server's OpenAPI spec.10.
When would you use function overloads instead of a union parameter?
AdvancedTechnicalPractise this question and get feedbackWhat the interviewer is evaluating
Designing precise public APIs.
Key points a strong answer covers
- Return type depends on input. Overloads let the return type depend on which argument shape was passed.
- Overload signatures + implementation. You write several call signatures and one implementation signature that's not visible to callers.
- Alternatives. Often a generic or a union parameter is simpler.
- Readability. Overloads give callers precise autocomplete and errors.
Suggested answer structure
- Define it in one sentence.
- Explain how it works underneath.
- Give a practical example from code or a project.
- Close with a trade-off, pitfall or when you'd use it.
Common mistakes
- Using overloads where one union signature is enough.
- Not knowing the implementation signature isn't callable.
Likely follow-up questions
- How would you type
createElement('a')returningHTMLAnchorElement? - What's the order rule for overload signatures?
Example strong answer
I use overloads when the return type depends on the shape of the input in a way a single union can't express. For example,
parse(input: string): Docandparse(input: string[]): Doc[]— with a union parameter the caller would getDoc | Doc[]and have to narrow it. With overloads you declare each call signature, then one implementation signature that handles all cases; callers only see the overloads. TypeScript picks the first matching overload, so specific signatures go first. Often a generic or conditional type works too, but overloads usually give clearer autocomplete and error messages, which matters for shared utilities.
Ready to answer them out loud?
Run a timed typescript developer mock interview, type or speak your answers, and get a score breakdown with what to improve.