🔷 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, boolean
null, undefined, void
any, unknown, never
array: T[] or Array<T>
tuple: [string, number]

📋 Interface vs Type

Interface: Extendable, declaration merging
Type: Unions, intersections, primitives
interface extends
type = A | B (union)
type = A & B (intersection)

🔄 Generics

<T> - Type parameter
<T extends U> - Constraint
<T = Default> - Default type
keyof T - Keys of type
T[K] - Indexed access

🛠️ Utility Types

Partial<T> - All optional
Required<T> - All required
Pick<T, K> - Select keys
Omit<T, K> - Exclude keys
Record<K, V> - Key-value map

🛡️ Type Guards

typeof - Primitive check
instanceof - Class check
in - Property check
is - Custom type guard
as - Type assertion

🚀 Advanced Types

Conditional: T extends U ? X : Y
Mapped: [K in keyof T]
infer - Extract type
as const - Literal type
satisfies - Type validation

⚠️ Common Interview Gotchas

• any disables type checking (avoid it)
• unknown is safer than any
• Interface can be merged, type cannot
• readonly vs const (properties vs variables)
• Structural typing (duck typing)
• Type narrowing with control flow

Both define object shapes, but interfaces support declaration merging and extension, while types support unions, intersections, and primitives.

typescript

Generics allow creating reusable components that work with multiple types while maintaining type safety.

typescript

Utility types are built-in TypeScript types that transform other types. They help avoid repetitive type definitions.

typescript

any bypasses type checking, unknown requires type checking before use, and never represents impossible values.

typescript

Type guards are expressions that narrow a type within a conditional block. TypeScript uses control flow analysis to track types.

typescript

Mapped types create new types by transforming each property of an existing type using a mapping syntax.

typescript

Conditional types select one of two types based on a condition, using the syntax T extends U ? X : Y.

typescript

Decorators are special declarations that modify classes, methods, properties, or parameters. They use the @expression syntax.

typescript

TypeScript provides strict null checks and operators like optional chaining (?.) and nullish coalescing (??) to handle null/undefined safely.

typescript

Declaration merging combines multiple declarations with the same name into a single definition. This works with interfaces, namespaces, and enums.

typescript

Enums define a set of named constants. TypeScript supports numeric and string enums, with const enums for optimization.

typescript

Template literal types use template literal syntax to create new string literal types by combining and transforming other types.

typescript

React components can be typed using interfaces for props, generic types for flexibility, and specific types for hooks and events.

typescript

The infer keyword extracts and infers types within conditional types, allowing you to capture parts of complex types.

typescript

TypeScript uses structural typing (duck typing): types are compatible if they have the same structure, regardless of their declared names.

typescript

tsconfig.json configures the TypeScript compiler options, including strict type checking, module resolution, and output settings.

json

Key settings explained:

  • strict: Enables all strict type-checking options
  • target: ECMAScript version for output
  • module: 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.

typescript

Discriminated unions use a common literal property to distinguish between union members, enabling exhaustive type checking.

typescript

Type-safe event emitters use TypeScript generics and mapped types to ensure event names and payloads are correctly typed.

typescript

Module augmentation extends existing modules with new declarations. Global declarations add types to the global scope.

typescript

Interview Tips for TypeScript