75 TypeScript interview questions with answers
75 TypeScript interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All TypeScript interview questions
What is TypeScript and why should you use it instead of JavaScript?
What is type annotation in TypeScript?
What is the difference between any, unknown, and never?
What are union types and intersection types?
What are literal types in TypeScript?
What is type narrowing? What are the ways to narrow a type in TypeScript?
What is the as keyword (type assertion)? When should you use it?
What is the non-null assertion operator (!)?
What is a tuple type in TypeScript?
What are enums in TypeScript? How do numeric and string enums differ?
What is the satisfies operator in TypeScript?
What is a const assertion (as const)?
What does TypeScript strict mode include?
What is the difference between interface and type alias? When do you use each?
How do you extend interfaces and types in TypeScript?
What is an index signature in TypeScript?
What are optional properties (?) and readonly properties?
What are discriminated unions? Why are they useful?
What is module augmentation?
What are recursive types in TypeScript?
What are branded types (nominal types) in TypeScript?
What is excess property checking in TypeScript?
What are generics in TypeScript? Why are they necessary?
What are generic constraints (extends) in TypeScript?
What is the keyof operator?
What are mapped types in TypeScript?
What are conditional types in TypeScript?
What is the infer keyword in conditional types?
What are template literal types in TypeScript?
What are recursive conditional types?
What are the utility types `Parameters<T>` and `ConstructorParameters<T>`?
How do generic functions with multiple type parameters work?
What are `Partial<T>` and `Required<T>`?
What is `Record<K, V>`? How does it differ from an index signature?
What are `Pick<T, K>` and `Omit<T, K>`?
What are `Exclude<T, U>` and `Extract<T, U>`?
What are `ReturnType<T>` and `Awaited<T>`?
What is `NonNullable<T>`?
What are `Readonly<T>` and `ReadonlyArray<T>`?
Implement `Partial<T>` from scratch to understand how it works.
How do you create deep partial and deep readonly types?
What are type guards? What types of type guards exist in TypeScript?
What are user-defined type guards (type predicates)?
What are decorators in TypeScript?
What are decorator metadata and reflect-metadata?
What are function overloads in TypeScript?
What are declaration files (.d.ts)?
What are the most important tsconfig.json options?
What is the distributive behavior of conditional types? How do you disable it?
What are generics in React components in TypeScript?
How do you type React hooks with TypeScript?
How do you type React events in TypeScript?
What are assertion functions in TypeScript?
Why does TypeScript use structural typing instead of nominal typing?
When should you use discriminated unions vs class hierarchies?
What is exhaustiveness checking in TypeScript?
What are path aliases in TypeScript (paths config)?
What are type-only imports and exports?
Why can TypeScript type checking be slow, and how do you improve it?
Your codebase mixes `type` and `interface`. What convention would you settle on, and why?
What errors typically appear when you enable `strictNullChecks` on a legacy codebase, and how should you fix them?
For a fixed set of values (order status, role), would you use an `enum` or a union of string literals?
What type does `await res.json()` return? Is `const user = await res.json() as User` safe?
How would you model a screen state (loading / success / error) with types?
Why does narrowing get "lost" after calling another function or inside a callback, and how do you work around it?
For a config object, how do `satisfies T`, `as T`, and the annotation `: T` differ?
Why does passing a string variable into a union-typed parameter fail, yet adding `as const` fixes it?
Write a type-safe `pick(obj, keys)`. Why is `K extends keyof T` needed?
When does TypeScript infer a generic as `string` instead of a literal, and how do you force narrow inference?
What are mapped types with key remapping (`as`) for? Show generating getters and renaming keys.
How do you use conditional types with `infer` to extract inner types (array element, Promise value)? What trap does distributivity create?
How would you write `DeepPartial<T>` and `RequireAtLeastOne<T>`? What are the recursion traps with arrays, `Date`, and functions?
What are template literal types used for in practice (routes, event names)? What are their limits?
You need to add a `user` field to Express's `Request`, or extend an auth library's session. Where and how do you declare it?
Why does assigning an object literal with an extra field error, while assigning it through an intermediate variable does not?