🔷
Free Study Guide · 2025
Top 15 TypeScriptInterview Questions & Answers (2025)
TypeScript is now expected in most frontend and full-stack roles at Indian product companies. These questions cover everything from basic type annotations to advanced generics and utility types asked at Razorpay, CRED, Zepto, and modern startups.
✓ 15 questions
✓ Detailed answers
✓ 100% free
1What is TypeScript and why do you use it?▼
TypeScript is a statically-typed superset of JavaScript developed by Microsoft that compiles to plain JavaScript. It adds optional static typing, interfaces, enums, generics, and better tooling (autocomplete, error detection at compile time). Benefits: catches type errors before runtime, improves code documentation through types, and enables safer refactoring. It's the default choice for new React and Node.js projects.
2What is the difference between type and interface?▼
Both define the shape of an object. Key differences: interfaces can be extended with extends and merged via declaration merging (defining the same interface twice merges them). Type aliases can represent primitives, unions, tuples, and mapped types — more expressive. For object shapes, either works; prefer interface for public APIs (declaration merging is useful) and type for unions, intersections, and complex type expressions.
3What are generics in TypeScript?▼
Generics allow you to write reusable code that works with multiple types while maintaining type safety. function identity<T>(arg: T): T { return arg; } — the T is a type variable that's determined at call time. Generics are used throughout TypeScript's standard library: Array<T>, Promise<T>, Map<K,V>. Constraints (<T extends object>) narrow what types are accepted.
4What is the difference between any, unknown, and never?▼
any disables type checking entirely — avoid it as it defeats TypeScript's purpose. unknown is type-safe any — you must narrow the type with typeof or instanceof before using it. never represents a value that never occurs — the return type of functions that always throw, infinite loops, or branches that are logically impossible. It's also the bottom type (no value is assignable to never).
5What are union types and intersection types?▼
A union type (A | B) means a value can be of type A or B. A function accepting string | number handles both. An intersection type (A & B) combines multiple types — a value must satisfy all of them. Intersections are used to compose types: type Admin = User & { adminLevel: number }. Use unions for alternatives; use intersections for combinations.
6What are TypeScript utility types?▼
Built-in generic types that transform existing types: Partial<T> makes all properties optional; Required<T> makes all required; Readonly<T> makes all read-only; Pick<T, K> selects a subset of properties; Omit<T, K> excludes properties; Record<K, V> creates an object type; Exclude<T, U> removes union members; ReturnType<T> extracts a function's return type. Mastering these eliminates repetitive type definitions.
7What is type narrowing?▼
Type narrowing is TypeScript's ability to refine a type to a more specific type within a conditional block. It uses type guards: typeof (typeof x === 'string'), instanceof (x instanceof Date), truthiness checks, equality checks, and discriminated unions. Custom type predicates (function isString(x: any): x is string) let you create reusable narrowing functions.
8What is a discriminated union?▼
A discriminated union is a union of types that share a common literal property (the discriminant) allowing TypeScript to narrow to the correct type in a switch/if. Example: type Shape = { kind: 'circle'; radius: number } | { kind: 'rect'; width: number }. Switching on shape.kind lets TypeScript know the exact shape in each branch. It's the idiomatic TypeScript pattern for modelling variant types.
9What are TypeScript decorators?▼
Decorators are an experimental feature (enabled with experimentalDecorators) that add metadata and modify classes, methods, properties, or parameters using @syntax. They're central to Angular and used in NestJS for @Injectable(), @Controller(), @Get(). Under the hood they're functions that receive the decorated target as an argument. TypeScript 5.0 introduced the TC39 Stage 3 decorators proposal as the new standard.
10What is the difference between interface and abstract class in TypeScript?▼
An interface defines a contract (shape) with no implementation — multiple interfaces can be implemented. An abstract class can have implemented methods, constructors, and properties, but cannot be instantiated directly. A class can only extend one abstract class. Use interfaces for pure contracts; use abstract classes when you want to share partial implementations while enforcing a contract.
11What is declaration merging in TypeScript?▼
Declaration merging allows TypeScript to merge multiple declarations with the same name into a single definition. Most commonly used to extend third-party interfaces — you can add properties to the Express Request interface without modifying the library source. Also used to combine namespace declarations. Types cannot be merged; only interfaces and namespaces support this.
12What are mapped types in TypeScript?▼
Mapped types transform existing types by iterating over their keys. type Optional<T> = { [K in keyof T]?: T[K] } creates a type with all properties of T made optional. You can add (readonly) or remove (-readonly, -?) modifiers. Mapped types are the basis for Partial, Required, Readonly, and Record. Combined with conditional types, they enable very expressive type-level programming.
13What are conditional types?▼
Conditional types have the form T extends U ? X : Y — if T is assignable to U, the type is X; otherwise Y. Used in utility types: NonNullable<T> is T extends null | undefined ? never : T. The infer keyword within conditional types extracts type information: ReturnType<T> uses T extends (...args: any) => infer R ? R : never to extract the return type of a function type.
14What is strict mode in TypeScript?▼
TypeScript's strict flag in tsconfig.json enables a group of strict type-checking options: strictNullChecks (null and undefined are not assignable to other types), noImplicitAny (error on implicit any type), strictFunctionTypes, strictBindCallApply, and others. Always enable strict: true in new projects — it catches the most common bugs and is now the community standard.
15What is the difference between extends and implements in TypeScript?▼
extends is used for inheritance: a class that extends another gets all its methods and properties (and must call super() in the constructor). implements is used to satisfy an interface contract: the class must provide all the interface's required properties and methods but gets no implementation from the interface. A class can implement multiple interfaces but extend only one class.
Level up your prep
Get company-specific TypeScript questions
Upload your resume → get questions tailored to Google, Amazon, TCS, and 50+ companies.