Interview questions · Tech stack

TypeScript Interview Questions & Answers (2026)

These interviews test your grasp of static typing, compiler options, and advanced language features. Demonstrate clear understanding of type inference, generics, and declaration merging, and show how you apply them to write safe, maintainable code. Emphasize practical trade‑offs and real‑world usage to impress interviewers.

23 questions · updated Aug 29, 2026

Quick facts

Typical roundsPhone screen, technical coding, system design, and senior‑level deep dive
Core topicsTypes, interfaces, generics, modules, decorators, compiler config
Success tipExplain why a feature exists, not just how it works

Questions

Beginner

What is the difference between 'any' and 'unknown' types?

The 'any' type disables type checking, allowing any value without compile‑time safety, which can hide bugs. 'unknown' is a safer counterpart; you must narrow it before use, preserving type safety. Interviewers expect you to discuss when to prefer 'unknown' for external data and how it forces explicit checks, showing disciplined typing.

let val: unknown = fetchData(); if (typeof val === 'string') { console.log(val.toUpperCase()); }
GoogleMicrosoft

How does TypeScript's type inference work?

TypeScript infers types from initial values, function return statements, and contextual usage. For example, const x = 5 infers number, and a function returning x infers number as well. Interviewers look for you to explain that inference reduces explicit annotations while still catching mismatches, and that you can override it with explicit types when needed for clarity.

const count = 10; // inferred as number
Amazon

When would you use an interface versus a type alias?

Both can describe object shapes, but interfaces are extendable via declaration merging and support implements clauses, making them ideal for public contracts. Type aliases can represent unions, tuples, or mapped types, offering more flexibility. Interviewers expect you to choose interfaces for API contracts and type aliases for complex compositions, highlighting the trade‑off.

interface User { id: number; name: string; }
type Result = Success | Failure;
Facebook

How do you enforce immutability in TypeScript?

Use the 'readonly' modifier on properties and arrays, and combine it with 'as const' for literal values. You can also define immutable interfaces and avoid mutable methods. Interviewers look for you to discuss why immutability reduces side effects and how TypeScript helps enforce it at compile time.

interface Point { readonly x: number; readonly y: number; }
Google

What are the benefits and drawbacks of using 'any' in a large codebase?

'any' provides flexibility and quick prototyping, but it erodes type safety, allowing runtime errors to slip through. In large codebases it hampers refactoring and IDE assistance. Interviewers expect you to recommend limiting 'any', using 'unknown' or generics instead, and applying lint rules to catch accidental usage.

Facebook

Explain the role of 'tsconfig.json' in a TypeScript project.

tsconfig.json defines compiler options, file inclusion, and project structure. It controls strictness flags, module resolution, target JavaScript version, and path aliases. Interviewers look for you to discuss how proper configuration enforces consistency, enables incremental builds, and integrates with tooling like ESLint and Jest.

Netflix

Intermediate

Explain generics and give a practical example.

Generics allow you to write reusable components that work with any type while preserving type information. For instance, a function identity<T>(arg: T): T returns the same type it receives, enabling compile‑time safety. Interviewers want to see you use generics for collections, utility functions, and how you constrain them with extends to enforce required properties.

function identity<T>(arg: T): T { return arg; }
Netflix

What are mapped types and when are they useful?

Mapped types transform each property in a given type according to a rule, such as making all properties optional with Partial<T> or readonly with Readonly<T>. They are useful for creating utility types, enforcing consistency across similar objects, and building type‑safe APIs. Interviewers look for you to demonstrate a real‑world scenario like converting a DTO to a partial update payload.

type Partial<T> = { [P in keyof T]?: T[P]; }
Airbnb

How does declaration merging work with interfaces?

When multiple interface declarations share the same name, TypeScript merges their members into a single interface. This enables extending third‑party types without modifying source code. Interviewers expect you to show merging to add properties to library types or to split large interfaces across files, emphasizing maintainability.

interface Window { title: string; }
interface Window { version: number; } // merged
Microsoft

What is the purpose of the 'never' type?

The 'never' type represents values that never occur, such as functions that always throw or have infinite loops. It is used for exhaustive type checking, ensuring all union cases are handled. Interviewers want you to explain how 'never' helps catch missing branches in switch statements and improves type safety.

function fail(msg: string): never { throw new Error(msg); }
Google

What is the purpose of the 'as const' assertion?

'as const' tells the compiler to infer the most specific literal types and mark the object as readonly. This converts arrays to tuple types and object properties to literal unions, enabling precise type checking. Interviewers want you to show its use in defining immutable configuration objects or action types.

const COLORS = ['red', 'green'] as const; // type: readonly ['red','green']
Netflix

Explain how to use utility types like Pick and Omit.

Pick<T, K> creates a new type with only the selected keys K from T, while Omit<T, K> removes keys K. They are useful for shaping API request/response types, reducing duplication, and enforcing consistency. Interviewers expect you to illustrate with a User type and a UserPreview that picks only id and name.

type UserPreview = Pick<User, 'id' | 'name'>;
Facebook

What is a discriminated union and how does it improve type safety?

A discriminated union combines a common literal property (the discriminant) with multiple interfaces, allowing the compiler to narrow the type based on that property. This enables exhaustive checks in switch statements, preventing invalid states. Interviewers expect a concrete example like shape types with a 'kind' field.

type Shape = { kind: 'circle'; radius: number } | { kind: 'square'; side: number };
Microsoft

How do you handle circular dependencies in TypeScript modules?

Break the cycle by extracting shared types into a separate module, use lazy imports, or employ interfaces to decouple implementations. You can also use 'import type' to import only types, which are erased at runtime, reducing circular runtime dependencies. Interviewers look for practical refactoring strategies.

Amazon

Advanced

Describe how to configure strict null checks and why they matter.

Enable 'strictNullChecks' in tsconfig.json to treat null and undefined as distinct from other types. This forces explicit handling of nullable values, reducing runtime errors. Interviewers look for you to discuss the impact on legacy code, how to migrate gradually, and the benefit of catching null‑related bugs at compile time.

"strictNullChecks": true
Amazon

What are conditional types and how do they differ from union types?

Conditional types evaluate a type relationship and return one of two possible types, using the syntax T extends U ? X : Y. Unlike unions, which accept any member, conditional types compute a specific result based on type compatibility. Interviewers expect you to illustrate with a utility like ReturnType<T> and discuss inference and distributive behavior.

type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
Netflix

How do you create a branded type to avoid accidental mixing of similar primitives?

Branding adds a unique phantom property to a primitive, creating a distinct type without runtime overhead. For example, type UserId = string & { readonly brand: unique symbol; }. This prevents mixing UserId with plain strings, and you provide a factory function to cast safely. Interviewers want to see you protect APIs from subtle bugs.

type UserId = string & { readonly __brand: unique symbol; }
Airbnb

Explain the difference between 'export =' and 'export default' in module systems.

'export =' is used for CommonJS compatibility, allowing a module to expose a single object that can be imported with require(). 'export default' follows ES6 syntax, enabling default imports. Interviewers expect you to discuss interop scenarios, when to use each, and how tsconfig's 'esModuleInterop' flag affects the behavior.

export = myLib; // CommonJS
export default myComponent; // ES6
Microsoft

What are declaration files (.d.ts) and when should you write them?

Declaration files describe the shape of existing JavaScript code to the TypeScript compiler, providing type information without implementation. Write them for third‑party libraries lacking typings, for internal JS modules, or to expose public APIs. Interviewers look for you to explain how .d.ts files enable gradual adoption and improve IDE assistance.

// myLib.d.ts
export function foo(arg: string): number;
Google

How does the 'keyof' operator work with generic constraints?

'keyof' produces a union of property names of a type. When combined with a generic constraint like <T extends object>, keyof T lets you create functions that operate on any object's keys, enabling type‑safe property access. Interviewers expect a demonstration such as a pick<T, K extends keyof T>(obj, keys) utility.

function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> { /*...*/ }
Amazon

How does TypeScript handle overloads and what should you watch out for?

Function overloads are declared with multiple signatures followed by a single implementation. The compiler matches calls against the signatures, not the implementation. Be careful to keep overloads ordered from most specific to least specific and ensure the implementation can handle all cases. Interviewers want you to discuss how mismatched overloads cause confusing errors.

function fn(x: string): string;
function fn(x: number): number;
function fn(x: any): any { return x; }
Amazon

How can you improve build performance for a large TypeScript monorepo?

Enable incremental compilation with 'composite' projects, use project references to share type information, and limit the scope with 'include'/'exclude'. Additionally, leverage 'tsc --build' for parallel builds and cache results with tools like 'babel-loader' or 'esbuild'. Interviewers expect you to balance speed with type accuracy.

Google

What is the difference between structural and nominal typing in TypeScript?

TypeScript uses structural typing, meaning compatibility is based on shape rather than explicit declarations. Two types with identical members are assignable. Nominal typing requires explicit branding to differentiate otherwise identical structures. Interviewers want you to explain why structural typing eases integration but can cause accidental misuse, and how branding introduces nominal safety.

Microsoft

Common mistakes

  • Using 'any' instead of precise types or 'unknown'
  • Forgetting to enable strict null checks, leading to hidden bugs
  • Misusing overload signatures, causing mismatched call signatures
  • Neglecting to export types from declaration files, breaking imports
  • Over‑relying on type assertions, which bypass compiler safety

Study plan

  1. Review core type system: primitives, unions, intersections, and type inference
  2. Master generics, conditional types, and mapped types with hands‑on exercises
  3. Deep dive into compiler options, strict mode, and project configuration
  4. Practice writing declaration files and handling module interop scenarios
  5. Build a small full‑stack app, focusing on type safety across API boundaries

FAQ

How much TypeScript should I know for a senior role?

Senior positions expect mastery of the type system, compiler configuration, and ability to design type‑safe APIs. You should be comfortable with advanced features like conditional types, declaration merging, and performance‑aware project setups.

Can I use JavaScript libraries without type definitions?

Yes, but you should add a minimal .d.ts file or use 'any' cautiously. Interviewers prefer you to create proper typings or use 'unknown' to maintain safety.

What is the best way to practice TypeScript interview questions?

Implement real‑world scenarios, such as building a typed Redux store or a generic data fetch utility. Pair coding with a peer and explain your reasoning aloud.

How important is understanding the TypeScript compiler?

Very important. Knowing how tsc transforms code, resolves modules, and enforces strictness helps you debug issues and optimize builds, which senior interviewers often probe.

Should I focus on TypeScript syntax or type‑system concepts?

Both matter, but concepts like variance, inference, and conditional types carry more weight. Syntax is easy to recall; deep understanding demonstrates problem‑solving ability.

Related

Ready for your next interview?

Download MiPrep AI. Load your resume and the job description. Show up ready.

Free tier · No credit card · macOS 14+ · Windows 10+

Free tier · No credit card · Runs on your Mac or Windows machine