TypeScript Interview Questions and Answers
TypeScript questions show whether you use the type system to catch bugs or only to silence the compiler with `any`. Interns are asked what TypeScript adds on top of JavaScript; mid-level and senior candidates are asked to model real data with generics, unions and narrowing.
Usually asked in frontend, backend and full stack interviews, from intern / fresher to senior (5+ years).
Intern / Fresher
- Q1Intern / FresherWhat is TypeScript and why do we use it?
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It catches type errors in the editor and at build time, and it documents the shape of data for the next person who reads the code.
- Q2Intern / FresherWhat is the difference between interface and type in TypeScript?
Both describe object shapes. interface can be merged and is preferred for public object contracts; type can express unions, intersections and primitives, and cannot be reopened later.
Junior (0-2 years)
- Q1Junior (0-2 years)What is the difference between any, unknown and never in TypeScript?
any turns off checking. unknown is a type-safe any: you must narrow it before use. never means a value cannot exist, used for exhaustive checks and functions that always throw.
- Q2Junior (0-2 years)What are generics in TypeScript?
Generics are type parameters: they let a function, class or type work with many types while keeping the relationship between inputs and outputs, instead of falling back to any.
- Q3Junior (0-2 years)What are union and intersection types in TypeScript?
A union (A | B) is a value that is one of the members. An intersection (A & B) is a value that must satisfy both types at once.
- Q4Junior (0-2 years)What are utility types in TypeScript like Partial, Pick and Omit?
Utility types are built-in helpers that transform an existing type: Partial makes every field optional, Required the opposite, Pick keeps a set of keys, Omit removes them, and Record builds a key/value map.
Mid-level (2-5 years)
- Q1Mid-level (2-5 years)What is type narrowing in TypeScript?
Narrowing is when TypeScript shrinks a wide type (such as a union) to a more specific type after a runtime check like typeof, instanceof, in, or a custom type guard.
- Q2Mid-level (2-5 years)What is the difference between enum and union types in TypeScript?
A string union such as "admin" | "user" exists only in the type system and erases to plain strings. A TypeScript enum compiles to a JavaScript object (unless it is a const enum), which is extra runtime code and a weaker default.
- Q3Mid-level (2-5 years)How does TypeScript type inference work?
TypeScript fills in types you omit: literals get their literal or widened type, function return types are inferred from return statements, and generic arguments are inferred from the values you pass.
Senior (5+ years)
- Q1Senior (5+ years)What are mapped types and conditional types in TypeScript?
Mapped types build a new object type by looping over keys (`{ [K in keyof T]: ... }`). Conditional types pick a result with `T extends U ? X : Y`, which is how many utility types are implemented.