TypeScript interview questions
100 Frontend Engineering practice questions. Read what a strong answer covers, then practise it out loud against the clock.
Practise TypeScript questionsBeginner
- "Object is possibly undefined" error
- "Property does not exist on type" error
- A function returns different types in different cases
- Accessing input value from event.target causes an error
- Adding TypeScript to an existing JavaScript project
- any vs unknown
- Arrays and tuples in TypeScript
- Basic types in TypeScript
- Choosing between interface and type for a data model
- Classes and access modifiers in TypeScript
- Declaration files and @types packages
- Enums and their alternatives
- Generics basics
- Handling null and undefined with strictNullChecks
- Interfaces vs type aliases
- Intersection types
- Literal types
- Optional properties and parameters
- Reducing the use of any in a codebase
- Structural typing in TypeScript
- The never type
- The readonly modifier
- tsconfig basics and strict mode
- Type annotations vs type inference
- Type assertions
- Type narrowing basics
- Typing a callback parameter
- Typing a function that accepts several input shapes
- Typing an API response
- Typing an object with dynamic keys
- Typing functions
- Union types
- Using a library that has no TypeScript types
- What TypeScript is and why teams use it
Intermediate
- A confusing excess property error
- A library's type definitions are wrong
- as const assertions
- Built-in utility types
- Conditional types
- Declaration merging and module augmentation
- Discriminated unions
- Ensuring every case of a union is handled
- Excess property checks
- Function overloads
- Generic constraints
- Important strictness compiler options
- Indexed access types
- Keeping runtime validation and types in sync
- keyof and typeof type operators
- Mapped types
- Migrating a large JavaScript codebase to TypeScript gradually
- Preventing mix-ups between different ID types
- Sharing types between frontend and backend
- Template literal types
- The satisfies operator
- Type assertions hide bugs
- Type checking is slow in a monorepo
- Type-only imports and exports
- Types have become too complex to understand
- Typing a generic fetch helper
- Typing a reducer's actions
- Typing an event emitter with known events
- Typing environment variables and configuration
- Typing partial update payloads
- Upgrading TypeScript breaks the build
- User-defined type guards
- Writing a type-safe sortBy utility
Experienced
- A type-only change broke library consumers
- A type-safe event bus across micro-frontends
- Advanced generic patterns for fluent APIs
- Authoring TypeScript libraries and declaration output
- Building type-safe forms
- Debugging cryptic TypeScript error messages
- Designing the types for a public SDK
- Distributive conditional types
- Emulating nominal typing in TypeScript
- Enforcing TypeScript strictness across an organisation
- Generating a type-safe API client from an OpenAPI spec
- How TypeScript inference works in depth
- Inconsistent TypeScript configs across a monorepo
- Migrating from enums to union types
- Modelling a complex workflow with discriminated union state
- Needing deep partial and deep readonly types
- Production bugs despite passing type checks
- Publishing a package with correct types for ESM and CommonJS
- Recursive types
- Removing thousands of any types from a legacy codebase
- The infer keyword
- Type checking takes many minutes in CI
- Type erasure, isolatedModules and fast transpilers
- Type-level programming trade-offs
- Type-safe feature flags
- Type-safe routing parameters
- Type-safe translation keys
- TypeScript compiler performance at scale
- TypeScript's type system soundness and its gaps
- Typing a generic data table component
- Typing a higher-order function that wraps any function
- Typing a plugin system
- Variance in TypeScript