Interview preparation

TypeScript Interview Questions

Answers written to be said out loud in an interview — each with a common follow-up question and a link to the tutorial that explains it in depth.

Beginner
8
Intermediate
12
Experienced
6
01What is the difference between interface and type?Beginner

Both describe object shapes. Interfaces can be re-opened (declaration merging) and extended with extends. Type aliases can also name unions, tuples and mapped types. For object shapes, either works; teams usually pick one convention.

Learn more: TypeScript — Interfaces
02What is TypeScript and why use it?Beginner

A superset of JavaScript that adds static types. The compiler catches type errors before runtime, editors give better autocompletion and refactoring, and types document how code is meant to be used.

Learn more: TypeScript — Introduction to TypeScript
03any vs unknown vs never?Beginner

any disables type checking. unknown accepts any value but forces you to narrow it before use — the safe choice for untrusted data. never represents values that never occur, such as a function that always throws or an exhaustive switch default.

Learn more: TypeScript — Basic Types
04Does TypeScript run in the browser?Beginner

No. The compiler (tsc, or a bundler such as Vite with esbuild) removes the types and outputs plain JavaScript. Types exist only at compile time, so they cannot validate data arriving from an API at runtime.

Learn more: TypeScript — JavaScript vs TypeScript
05What is type inference?Beginner

TypeScript works out types from values, so let count = 0 is a number without an annotation. Annotate function parameters, public APIs and empty values, and let inference handle the rest.

Learn more: TypeScript — Type Inference
06Arrays vs tuples?Beginner

An array type (string[]) holds any number of items of one type. A tuple ([string, number]) has a fixed length with a type per position — useful for returning pairs like React’s useState.

Learn more: TypeScript — Arrays and Tuples
07How do optional and default parameters differ?Beginner

An optional parameter (name?: string) may be omitted and is typed string | undefined. A default parameter (name = "Guest") is also optional to the caller but always has a value inside the function.

Learn more: TypeScript — Optional and Default Parameters
08What are literal types?Beginner

Types that allow only specific values: "sm" | "md" | "lg" or 200 | 404. They make invalid values impossible and give autocomplete in the editor.

Learn more: TypeScript — Literal Types
09Why use generics instead of any?Intermediate

Generics preserve the relationship between input and output types, so the compiler still checks your code. any disables checking entirely.

Learn more: TypeScript — Generics
10What are union and intersection types?Intermediate

A union (A | B) is a value of either type. An intersection (A & B) combines types so the value has all members of both.

Learn more: TypeScript — Union and Intersection Types
11What is type narrowing?Intermediate

Refining a broad type to a more specific one inside a code path using checks such as typeof, instanceof, in, equality checks, truthiness or user-defined type guards (value is Type).

Learn more: TypeScript — Type Narrowing
12Name some built-in utility types.Intermediate

Partial<T>, Required<T>, Readonly<T>, Pick<T, K>, Omit<T, K>, Record<K, V>, ReturnType<F>, Parameters<F>, NonNullable<T> and Awaited<T>.

TypeScript Illustrative
type UpdateUser = Partial<Omit<User, "id">>;
Learn more: TypeScript — Utility Types
13What does "strict": true enable?Intermediate

A group of checks including strictNullChecks, noImplicitAny, strictFunctionTypes, strictPropertyInitialization and useUnknownInCatchVariables. It catches many real bugs and should be on for new projects.

Learn more: TypeScript — Strict Mode
14What is a type guard?Intermediate

A runtime check that narrows a type inside a branch: typeof, instanceof, the in operator, equality checks, or a custom function returning value is Type.

TypeScript Illustrative
interface Cat { meow(): void }
interface Dog { bark(): void }
function isCat(pet: Cat | Dog): pet is Cat {
  return 'meow' in pet;
}
Learn more: TypeScript — Type Guards
15What is a discriminated union?Intermediate

A union of object types that share a literal property such as kind or status. Checking that property narrows to one member, and a never check in the default branch makes the switch exhaustive.

Learn more: TypeScript — Type Narrowing
16How do you constrain a generic?Intermediate

With extends: function getId<T extends { id: number }>(item: T) accepts any object with a numeric id and keeps its full type. keyof constraints (K extends keyof T) make property-access helpers type-safe.

Learn more: TypeScript — Generics
17What do public, private, protected and readonly do in TypeScript classes?Intermediate

public is accessible everywhere, protected in the class and subclasses, private only in the class (at compile time). readonly can be set only in the declaration or constructor. Parameter properties (constructor(private repo: Repo)) declare and assign in one step.

Learn more: TypeScript — Access Modifiers
18What is the difference between abstract classes and interfaces in TypeScript?Intermediate

An interface is only a type and disappears at runtime. An abstract class exists at runtime, can hold shared implementation and constructor logic, and cannot be instantiated directly.

Learn more: TypeScript — Abstract Classes
19How do you type async functions?Intermediate

An async function returns Promise<T>. Annotate it explicitly on public functions, type fetched JSON (await res.json() is any), and use Awaited<T> to unwrap promise types.

Learn more: TypeScript — Async Programming
20Which tsconfig options matter most?Intermediate

strict (all strict checks), target and module (output), moduleResolution (bundler or node16), noUncheckedIndexedAccess, skipLibCheck, paths for aliases, and noEmit when a bundler compiles the code.

Learn more: TypeScript — tsconfig.json
21Explain keyof and typeof in type positions.Experienced

keyof T produces a union of T’s property names. typeof value gets the type of a runtime value. Together they derive types from existing data, e.g. type Key = keyof typeof config.

Learn more: TypeScript — keyof and typeof
22Enums vs union of string literals?Experienced

Enums generate runtime JavaScript objects; string literal unions ("draft" | "published") exist only at compile time, produce no output and work well with plain JSON. Many teams prefer literal unions or as const objects.

Learn more: TypeScript — Enums
23What are mapped and conditional types?Experienced

Mapped types build new types by looping over keys: { [K in keyof T]?: T[K] } is how Partial works. Conditional types choose a type with T extends U ? X : Y, and infer extracts parts, as in ReturnType.

Learn more: TypeScript — Utility Types
24How do you type React props and events?Experienced

Describe props with an interface or type, use React.ComponentProps<"button"> to extend native props, type events as React.ChangeEvent<HTMLInputElement>, and let useState infer unless the initial value is null.

Learn more: TypeScript — TypeScript with React
25How does TypeScript help in Angular?Experienced

Angular is written in TypeScript: decorators, DI tokens, typed reactive forms, strict template type checking and typed HttpClient responses (http.get<Product[]>()) all depend on it.

Learn more: TypeScript — TypeScript with Angular
26When is a type assertion (as) dangerous?Experienced

An assertion tells the compiler to trust you and checks nothing at runtime. as unknown as T can turn any value into anything. Prefer narrowing, satisfies, or runtime validation (zod) for external data.

Learn more: TypeScript — Type Narrowing