Explore All 4,300+ Interview Questions
Filter, search, and practice across the entire engineering curriculum. Filter by seniority level, high-frequency interview patterns, runnable code solutions, and individual technology tracks.
Personalized Interview Tech Stack
Select the technologies on your resume to tailor questions and cheatsheets.
What is TypeScript and how does it relate to JavaScript?
TypeScript is a strongly typed programming language developed by Microsoft that builds on JavaScript by adding optional static typing.: Syntactic Superset: Any valid JavaScript code is automatically valid TypeScript code (.js files can be renamed to .ts) • Compile-Time Only: Browsers and Node.js cannot execute TypeScript directly.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are Primitive Types vs Object Types in TypeScript?
Primitive Types: Built-in immutable JavaScript primitives: string, number, boolean, bigint, symbol, null, undefined • Object Types: Non-primitive structures: object, arrays (number[]), interfaces, classes, tuples, and functions • Convention Note: Always use lowercase primitive types (string, number, boolean).
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
Compare `any`, `unknown`, and `never`.
Type Meaning Type Safety Operations Allowed.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What is the difference between `type` alias and `interface`?
Both define the shape of objects, but they have key architectural differences.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
How do Function Signatures and Return Types (`void` vs `never`) work?
void: Indicates a function completes execution without returning a value (returns undefined implicitly) • never: Indicates a function never finishes successfully—either it throws an uncaught exception or enters an infinite loop (while(true)).
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
Why does modern TypeScript favor String Union Types over Enums?
Numeric and standard Enums in TypeScript generate real JavaScript code during compilation (creating reverse-mapping object tables).: Enums: Pollute the compiled bundle with runtime object overhead and can produce unsafe numeric assignments (enum Status { Active, Inactive }).
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are Tuples and `as const` assertions?
Tuple: An array with a fixed length and known types at specific indices: [string, number] • as const (Const Assertion): Tells the compiler to infer the most specific, literal, readonly type possible.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What is the difference between Type Assertions (`as`) and Type Casting?
Type Casting in languages like C# or Java converts data representations at runtime (e.g. converting float bytes to integer) • Type Assertion (as Type) in TypeScript is purely a compile-time instruction telling the compiler: "Trust me, I know the type better than you.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What is Structural Typing (Duck Typing)?
TypeScript uses structural typing, not nominal typing. Two types are considered identical if they have the same structure (shape), regardless of their declared names.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are Generics and why are they necessary?
Generics allow you to write reusable, type-safe functions, classes, and interfaces that work over a variety of types rather than a single fixed type, capturing the argument type dynamically.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
How do Generic Constraints (`extends`) work?
By default, generic T can be anything. Using T extends Shape constrains T to types that contain specific required properties.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What is the `keyof` operator and Indexed Access types?
keyof T: Produces a union of all property keys of type T • T[K] (Indexed Access): Extracts the type of a specific property K on type T.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are Discriminated Unions (Tagged Unions)?
A pattern where multiple object types share a common, unique literal property (the "discriminant" or "tag"). TypeScript automatically narrows the union inside a switch or if block.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
How do Type Narrowing and Custom Type Guards (`is`) work?
TypeScript automatically narrows types within conditional branches using: typeof x === 'string' • x instanceof Date • 'property' in obj.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are the essential flags in `tsconfig.json`?
"strict": true: Enables all strict type-checking options (the single most important flag) • "target": "ES2022": Target ECMAScript version for output JS • "module": "NodeNext": Module system for code generation • "noImplicitAny": true: Raises an error on any variable whose type defaults to any.
Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
What are Conditional Types and Distributive Conditional Types?
Conditional types choose one of two possible types based on a subtyping relationship: T extends U ? X : Y When a conditional type operates on a generic union type (a "naked" type parameter), it automatically distributes over each union member.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
How does the `infer` keyword work in conditional types?
infer allows you to declare a type variable inside the condition to extract or unwrap an unknown subtype.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are Mapped Types and Key Remapping (`as`)?
Mapped types build new types by transforming each property in an existing type.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are Template Literal Types?
Template literal types bring JavaScript template string interpolation syntax directly into the type system.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
Explain Standard Utility Types: `Partial`, `Required`, `Readonly`, `Record`.
PartialT: Makes all properties optional (?) • RequiredT: Removes all optional modifiers (-?) • ReadonlyT: Adds readonly to all properties • Record: Constructs an object type with property keys K and value type T.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
Explain Filtering Utility Types: `Pick`, `Omit`, `Exclude`, `Extract`.
Pick: Constructs a type by picking specific keys K from object T • Omit: Constructs a type by omitting keys K from object T • Exclude: Excludes from union T all members assignable to U • Extract: Extracts from union T all members assignable to U.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What is the `satisfies` operator in TypeScript 4.9+?
Before satisfies, you had a dilemma: If you annotated const palette: Colors = { .. • If you omitted the annotation const palette = { .
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
How do you implement a Deep Partial or Deep Readonly type?
Standard PartialT is shallow (only makes top-level keys optional). Using recursive conditional types, we can make every nested level optional.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are Overloaded Function Signatures?
Function overloading allows a function to accept different combinations of parameters and return different types. You define multiple public function signatures followed by a single private implementation.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are Ambient Declarations and `.d.ts` files?
Ambient declarations describe the shape of existing JavaScript code that has no built-in types (e.g., globals on window, external C-modules, or legacy npm packages). Defined using the declare keyword in .d.ts files. They contain zero executable JavaScript—only type definitions.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are `const` Type Parameters (TypeScript 5.0+)?
In TypeScript 5.0, you can prefix a generic parameter with const to enforce that calls automatically infer as const literal types without forcing callers to write as const manually!
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What is Variance in TypeScript (Covariance vs Contravariance)?
Variance describes how subtyping of complex types relates to subtyping of their component types: Covariance (Output positions): If Dog extends Animal, then Dog[] extends Animal[], and () => Dog extends () => Animal • Contravariance (Input/Parameter positions): Function parameters are contravariant under strictFunctionTypes.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What is the `asserts` condition operator?
The asserts keyword defines an assertion function. If the function returns without throwing, TypeScript narrows the type of the argument for all subsequent lines in that scope.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
What are Excess Property Checks?
TypeScript normally allows passing an object with extra properties where fewer properties are expected (structural typing). However, when passing an object literal directly, TypeScript triggers Excess Property Checks to prevent typos.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
How do ECMAScript Stage 3 Decorators work in TypeScript 5.x?
TypeScript 5.0 adopted the official ECMAScript standard Decorators (replacing the legacy experimentalDecorators flag). Decorators are functions applied to classes, methods, accessors, and fields to wrap or replace them.
Part 2: Advanced Type System & Metaprogramming (Mid-Level)
Explain the TypeScript Compiler Architecture and Compilation Pipeline.
The tsc compiler operates across five sequential stages: Scanner: Reads source text and converts characters into Tokens • Parser: Consumes tokens and builds the Abstract Syntax Tree (AST) • Binder: Traverses the AST and connects declarations to Symbols (scoping and symbol table) • Checker: The core of TypeScript.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How do you implement Nominal Typing (Branded Types) in TypeScript?
Because TypeScript is structurally typed, a UserId (string) and an OrderId (string) are completely interchangeable, leading to catastrophic runtime bugs where an order ID is passed into a user deletion function! Branded Types attach a unique compile-time phantom property.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How do you optimize TypeScript compilation speed in massive enterprise codebases?
skipLibCheck: true: Skips type-checking of all .d.ts declaration files inside node_modules (saves up to 50% compilation time) • incremental: true: Saves compilation state to a .tsbuildinfo cache file for fast incremental builds.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
What are Project References and Composite Projects?
In a monorepo with 50 packages, running tsc across all 50 packages in a single run exhausts memory and takes minutes.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How does Runtime Validation (Zod) synchronize with Compile-Time TypeScript?
TypeScript types vanish at runtime and cannot validate incoming API payloads from external users. Zod provides runtime schema validation that automatically infers static TypeScript types using z.infer.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How do you build a strongly-typed Event Emitter?
By mapping event names to their payload types, you can enforce that emit and on require exact payload signatures.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How do you implement Deep Tuple Reverse using Recursive Conditional Types?
Deep tuple reversal uses recursive conditional types with variadic tuple unpacking and the infer keyword to peel off the first element and append it to the recursively reversed tail. #### Code Example.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
How do you diagnose and debug slow types in a TypeScript codebase?
Complex recursive conditional types or massive union combinations can freeze tsc.: Run tsc --extendedDiagnostics: Displays total check time, number of types created, and memory usage • Run tsc --generateTrace trace_dir: Generates Chrome DevTools performance traces.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
What causes the error `Type instantiation is excessively deep and possibly infinite`?
TypeScript caps recursive type evaluations (around 1,000 recursive steps in modern versions) to prevent compiler stack overflows.: Cause: Recursive mapped types lacking a proper base case or operating over circular data structures.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)
Explain TypeScript Module Resolution Modes (`Node16`, `NodeNext`, `Bundler`).
Node16 / NodeNext: Adheres strictly to Node.js ESM rules (requires explicit file extensions in imports like import './utils.js', respects • Bundler: Introduced in TS 5.0 for modern bundlers (Vite, Webpack, Turbopack) that resolve extensions and paths without requiring .js extensions.
Part 3: Enterprise Architecture, Compiler Internals & Performance (Senior / Staff)