40 questions with answers
TypeScript questions show up in almost every modern frontend loop, usually as concept questions about the type system or as part of a coding round. These questions cover generics, narrowing, utility and conditional types, inference and how to type real application code.
1.What is the difference between `any`, `unknown` and `never` in TypeScript?
The escape hatch, the safe top type, and the empty bottom type.
2.What are conditional types and the `infer` keyword in TypeScript?
Type-level branching, pattern matching with infer, and distribution over unions.
3.What are discriminated unions in TypeScript and how do you enforce exhaustive handling?
Tagged unions that make impossible states unrepresentable, checked with never.
4.Explain generics and generic constraints in TypeScript
Type parameters that preserve relationships, constraints, defaults, const and NoInfer.
5.What is the difference between an interface and a type alias in TypeScript?
Declaration merging and extends vs unions, tuples and type-level computation.
6.Explain `keyof`, `typeof` and indexed access types in TypeScript
Deriving key unions, value types and property types from existing code.
7.What does the `satisfies` operator do in TypeScript and how is it different from a type annotation or `as`?
Validate against a type while keeping precise inference.
8.What does `strict` mode enable in TypeScript, and which extra flags are worth turning on?
The strict family, noUncheckedIndexedAccess, exactOptionalPropertyTypes and migration strategy.
9.What is structural typing in TypeScript and what are its implications?
Compatibility by shape, excess property checks, and when you need nominal types.
10.What is the difference between a type assertion and a type annotation in TypeScript?
Checking vs overriding the compiler, non-null assertions, and safer alternatives.
11.How does type narrowing work in TypeScript, and how do you write type guards?
Control-flow narrowing, user-defined and inferred type predicates, and assertion functions.
12.Do TypeScript types exist at runtime? How do you validate external data?
Type erasure, trust boundaries, schema validation and type stripping.
13.How do you type event handlers in React with TypeScript?
Synthetic event types, handler aliases, target vs currentTarget, and DOM listener types.
14.How do you type React component props in TypeScript?
Props types, ReactNode children, native element props, exclusive variants and React.FC.
15.Which built-in TypeScript utility types do you use most, and how do they work?
Partial, Pick, Omit, Record, ReturnType, Awaited and friends, plus their pitfalls.
16.What does `as const` do in TypeScript?
Const assertions for literal, readonly types and deriving unions from values.
17.What are assertion functions in TypeScript?
Functions that narrow by throwing: asserts condition and asserts value is T.
18.What are branded (nominal) types in TypeScript and why use them?
Phantom brands that stop same-shape values being mixed up and mark validated data.
19.How do access modifiers work in TypeScript classes, and how is `private` different from `#private`?
Compile-time vs runtime privacy, parameter properties, abstract and override.
20.What are `.d.ts` declaration files and when do you write them?
Types-only files for JS code, assets and globals, and how packages ship types.
21.What is declaration merging in TypeScript?
How interfaces, namespaces and enums merge, and how that powers global and module augmentation.
22.What are distributive conditional types in TypeScript?
How conditional types map over unions, how to disable it, and the never trap.
23.Should you use enums or union literal types in TypeScript?
Runtime enums vs erasable unions, as const objects, and modern toolchain constraints.
24.What are excess property checks in TypeScript and when do they apply?
Why fresh object literals reject unknown keys, and when the check doesn't fire.
25.What are function overloads in TypeScript and when should you use them?
Multiple call signatures with one hidden implementation, and the alternatives.
26.How do you write generic React components in TypeScript?
Type parameters that connect props, tsx syntax quirks, and wrappers that lose generics.
27.What are index signatures in TypeScript and what are their pitfalls?
Dictionaries vs exhaustive Records, noUncheckedIndexedAccess, and when to use Map.
28.What are mapped types in TypeScript and how does key remapping work?
Iterating keys to build types, modifiers, and as-based renaming and filtering.
29.What is module augmentation in TypeScript and when would you use it?
Extending library and global types with declare module and declare global.
30.How do you model immutability in TypeScript with `readonly`?
readonly modifiers, Readonly, readonly arrays and as const, and their limits.
31.What are template literal types in TypeScript and what are they useful for?
Building and parsing string literal types for handlers, routes and typed paths.
32.What are tuple types in TypeScript, including variadic and labeled tuples?
Fixed-position arrays, optional, rest and labeled elements, and variadic tuple types.
33.What are type-only imports in TypeScript and what does `verbatimModuleSyntax` do?
Why per-file transpilers need explicit type imports, and the modern tsconfig setup.
34.How do you type refs in React with TypeScript, and what changed in React 19?
DOM refs, mutable refs, ref as a prop, imperative handles and callback ref cleanups.
35.How do you type `useReducer` state and actions in TypeScript?
Discriminated-union actions, exhaustive reducers and typed dispatch.
36.Explain covariance, contravariance and invariance in TypeScript
How generic and function types relate under subtyping, strictFunctionTypes and in/out annotations.
37.What are `const` type parameters in TypeScript 5.0?
as const-style literal inference without caller ceremony.
38.How do decorators work in TypeScript, and how do standard decorators differ from experimental ones?
TS 5.0 standard decorators vs legacy experimentalDecorators, and their use cases.