🔷 TypeScript Interview Questions
Master TypeScript interviews with questions on types, interfaces, generics, and utility types
15-Minute TypeScript Cheatsheet
Quick reference for last-minute interview preparation
🎯 Basic Types
string, number, booleannull, undefined, voidany, unknown, neverarray: T[] or Array<T>tuple: [string, number]📋 Interface vs Type
interface extendstype = A | B (union)type = A & B (intersection)🔄 Generics
<T> - Type parameter<T extends U> - Constraint<T = Default> - Default typekeyof T - Keys of typeT[K] - Indexed access🛠️ Utility Types
Partial<T> - All optionalRequired<T> - All requiredPick<T, K> - Select keysOmit<T, K> - Exclude keysRecord<K, V> - Key-value map🛡️ Type Guards
typeof - Primitive checkinstanceof - Class checkin - Property checkis - Custom type guardas - Type assertion🚀 Advanced Types
Conditional: T extends U ? X : YMapped: [K in keyof T]infer - Extract typeas const - Literal typesatisfies - Type validation⚠️ Common Interview Gotchas
Both define object shapes, but interfaces support declaration merging and extension, while types support unions, intersections, and primitives.
Generics allow creating reusable components that work with multiple types while maintaining type safety.
Utility types are built-in TypeScript types that transform other types. They help avoid repetitive type definitions.
any bypasses type checking, unknown requires type checking before use, and never represents impossible values.
Type guards are expressions that narrow a type within a conditional block. TypeScript uses control flow analysis to track types.
Mapped types create new types by transforming each property of an existing type using a mapping syntax.
Conditional types select one of two types based on a condition, using the syntax T extends U ? X : Y.
Decorators are special declarations that modify classes, methods, properties, or parameters. They use the @expression syntax.
TypeScript provides strict null checks and operators like optional chaining (?.) and nullish coalescing (??) to handle null/undefined safely.
Declaration merging combines multiple declarations with the same name into a single definition. This works with interfaces, namespaces, and enums.
Enums define a set of named constants. TypeScript supports numeric and string enums, with const enums for optimization.
Template literal types use template literal syntax to create new string literal types by combining and transforming other types.
React components can be typed using interfaces for props, generic types for flexibility, and specific types for hooks and events.
The infer keyword extracts and infers types within conditional types, allowing you to capture parts of complex types.
TypeScript uses structural typing (duck typing): types are compatible if they have the same structure, regardless of their declared names.
tsconfig.json configures the TypeScript compiler options, including strict type checking, module resolution, and output settings.
Key settings explained:
strict: Enables all strict type-checking optionstarget: ECMAScript version for outputmodule: Module system (ESNext, CommonJS)paths: Path aliases for cleaner imports
Type assertions tell TypeScript to treat a value as a specific type. Use them when you know more about a type than TypeScript can infer.
Discriminated unions use a common literal property to distinguish between union members, enabling exhaustive type checking.
Type-safe event emitters use TypeScript generics and mapped types to ensure event names and payloads are correctly typed.
Module augmentation extends existing modules with new declarations. Global declarations add types to the global scope.
Interview Tips for TypeScript
- ✓ Know the difference between interface and type aliases
- ✓ Understand generics and how to apply constraints
- ✓ Master utility types: Partial, Pick, Omit, Record
- ✓ Know type guards and narrowing techniques
- ✓ Understand structural vs nominal typing
- ✓ Be familiar with mapped and conditional types
- ✓ Know when to use any vs unknown vs never
- ✓ Practice typing React components and hooks