TypeScript interview questions & answers
What are the most common TypeScript interview questions?
TypeScript is a strongly typed superset of JavaScript that adds optional static types, interfaces, and generics, compiling down to plain JavaScript that runs anywhere JavaScript does. Types are checked at compile time and erased at runtime, catching errors early and improving tooling and maintainability. Interviews test typing concepts, interfaces versus type aliases, generics, and how the type system narrows and infers types.
Updated 2026-06-18 · 14 real, commonly-asked questions with answers.
Key takeaways
- TypeScript is a strongly typed superset of JavaScript that adds optional static types, interfaces, and generics, compiling down to plain JavaScript that runs anywhere JavaScript does.
- Core areas to revise for TypeScript: Static typing & inference, Interfaces vs type aliases, Generics, Union & intersection types, Type narrowing & guards.
- This guide answers 14 of the most-asked TypeScript interview questions — rehearse them in OnJob's free AI mock interview.
Top 14 TypeScript interview questions
Q1.What is TypeScript and how does it relate to JavaScript?
TypeScript is a superset of JavaScript that adds static typing and other features on top of standard JavaScript syntax. Any valid JavaScript is valid TypeScript. A compiler (tsc) type-checks the code and transpiles it to plain JavaScript, because browsers and Node run JavaScript, not TypeScript. The types exist only at compile time and are erased from the emitted code.
Q2.What are the benefits of using TypeScript?
TypeScript catches type-related bugs at compile time rather than at runtime, provides rich editor support like autocompletion and safe refactoring, and makes large codebases easier to understand and maintain through explicit contracts. It also documents intent through types. The cost is a compilation step and the effort of writing types.
Q3.What is the difference between an interface and a type alias?
Both describe the shape of data. Interfaces are primarily for object shapes and support declaration merging (you can reopen and extend them), and they are often preferred for public APIs. Type aliases are more flexible: they can represent unions, intersections, primitives, and tuples in addition to object shapes, but cannot be reopened. Use interface for objects you may extend; use type for unions and complex compositions.
Q4.What are generics and why are they useful?
Generics let you write reusable components and functions that work over a type provided later, denoted with type parameters like <T>. For example, a function that returns its argument can be typed Identity<T>(arg: T): T, preserving the exact type. Generics give you type safety and reuse without resorting to any, so the relationship between inputs and outputs is preserved.
Q5.What is the difference between any, unknown, and never?
any disables type checking entirely, allowing any operation and defeating TypeScript's purpose. unknown is the type-safe counterpart: you can assign anything to it, but you must narrow it with a check before using it. never represents values that never occur, such as a function that always throws or the result of an exhaustive switch; no value is assignable to never.
Q6.What is type inference?
Type inference is TypeScript's ability to deduce a type automatically from context without an explicit annotation. For example, let x = 5 infers x as number, and a function's return type is inferred from its return statements. Inference reduces boilerplate while keeping type safety, so you annotate explicitly mainly at boundaries like function parameters and public APIs.
Q7.What are union and intersection types?
A union type (A | B) means a value can be one of several types, such as string | number, and you must narrow it before using type-specific operations. An intersection type (A & B) combines multiple types into one that has all their members, useful for merging object shapes. Unions express alternatives; intersections express composition.
Q8.What is type narrowing?
Type narrowing is when TypeScript refines a broad type to a more specific one within a code branch based on checks. Techniques include typeof guards, instanceof, equality checks, the in operator, and custom type guard functions. After narrowing, TypeScript knows the precise type, so it allows operations valid only for that narrowed type.
Q9.What is the difference between an interface and a class?
An interface is a compile-time-only contract describing the shape an object must have; it has no implementation and produces no JavaScript. A class is a runtime construct that has both structure and implementation and creates actual objects. A class can implement one or more interfaces to guarantee it satisfies their contracts. Interfaces define shape; classes provide behavior.
Q10.What are enums in TypeScript?
An enum is a way to define a set of named constants, improving readability over magic numbers or strings. Numeric enums auto-assign incrementing numbers starting at zero, while string enums assign explicit string values. Enums exist at runtime (unlike most types), so they add code to the output; union string-literal types are a lighter alternative when runtime presence is not needed.
Q11.What does the readonly modifier do?
The readonly modifier marks a property so it can be set only during initialization (in the declaration or constructor) and not reassigned afterward, enforced at compile time. Applied to arrays via ReadonlyArray or readonly tuple types, it prevents mutation methods. It signals immutability intent and helps prevent accidental changes, though it is erased at runtime.
Q12.What is the difference between optional and nullable properties?
An optional property, marked with a question mark like name?: string, may be absent from the object entirely, giving it the type string | undefined. A nullable property is one whose type explicitly includes null, such as name: string | null, meaning it must be present but can hold null. Optional is about presence; nullable is about an explicit null value.
Q13.What are utility types like Partial and Pick?
Utility types are built-in generic types that transform existing types. Partial<T> makes all properties of T optional; Required<T> makes them all required; Pick<T, K> selects a subset of properties; Omit<T, K> removes properties; and Readonly<T> makes them read-only. They let you derive new types from existing ones without rewriting them, keeping types DRY.
Q14.What is a tuple in TypeScript?
A tuple is an array with a fixed number of elements whose types are known and may differ, declared like [string, number]. It enforces both the length and the type at each position, unlike a regular array where all elements share one type. Tuples are useful for representing a fixed structure, such as a key-value pair or a function returning multiple typed values.
More interview topics
- Data Structures & Algorithms (DSA)
- DBMS (Database Management)
- Operating Systems
- Computer Networks
- OOP (Object-Oriented Programming)
- System Design
- SQL
- Aptitude (Quantitative & Logical)
- Java
- Python
- JavaScript
- React
- AWS (Amazon Web Services)
- Docker
- Kubernetes
- Node.js
- Angular
- Git & Version Control
- REST APIs & Microservices
- Machine Learning
- Behavioral & HR
Practise & prepare
Practise TypeScript out loud
Reading answers is step one. Rehearse them in OnJob's free AI mock interview, get instant feedback, then apply to AI-matched jobs in one click.