Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →

Top TypeScript Interview Questions and Answers

The TypeScript interview questions asked most often, covering interfaces vs types, any vs unknown, generics, narrowing, utility types and keyof.

jiocoder TeamUpdated Oct 7, 20263 min readTypeScript
Top TypeScript Interview Questions and Answers

TypeScript is now expected in most frontend and Node.js roles. These questions test whether you can use the type system confidently, not just add type annotations.

1. What is TypeScript and what are its benefits?#

TypeScript is a superset of JavaScript that adds static types. It's compiled to plain JavaScript before running. Its main benefits are catching errors before runtime, better autocomplete and refactoring in editors, and code that documents itself.

Note

Types are removed when TypeScript compiles. They don't exist at runtime, so they can't validate data coming from an API. Use a runtime validator like Zod for that.

2. What is the difference between interface and type?#

Both describe the shape of an object. An interface can be extended and can be merged by declaring it twice. A type alias can also describe unions, tuples and primitives. A common rule: use interface for object shapes and public APIs, and type for unions and more complex types.

TypeScript
interface User {
  id: number;
  name: string;
}

type Status = "active" | "inactive" | "banned";
type Point = [number, number];

3. What is the difference between any, unknown and never?#

  • any: turns off type checking. Avoid it.
  • unknown: can hold any value, but you must narrow it before using it. The safe alternative to any.
  • never: a value that can never happen, like a function that always throws, or an impossible case in a switch.
TypeScript
function parse(input: unknown) {
  if (typeof input === "string") {
    return input.toUpperCase(); // OK: narrowed to string
  }
}

4. What are generics?#

Generics let you write reusable code that works with many types while keeping type safety. The type is passed in like a parameter.

TypeScript
function first<T>(items: T[]): T | undefined {
  return items[0];
}

const n = first([1, 2, 3]);     // number | undefined
const s = first(["a", "b"]);    // string | undefined

5. What are union and intersection types?#

A union (A | B) is a value that can be either type. An intersection (A & B) is a value that has all properties of both types.

TypeScript
type Id = string | number;

type Timestamps = { createdAt: Date };
type Post = { title: string } & Timestamps;

6. What is type narrowing?#

Narrowing is how TypeScript works out a more specific type inside a block. You narrow with typeof, instanceof, the in operator, equality checks, or a discriminated union.

TypeScript
type Shape =
  | { kind: "circle"; radius: number }
  | { kind: "square"; size: number };

function area(shape: Shape) {
  switch (shape.kind) {
    case "circle": return Math.PI * shape.radius ** 2;
    case "square": return shape.size ** 2;
  }
}

7. Name some built-in utility types#

UtilityWhat it does
Partial<T>Makes every property optional.
Required<T>Makes every property required.
Readonly<T>Makes every property read-only.
Pick<T, K>Keeps only the listed properties.
Omit<T, K>Removes the listed properties.
Record<K, V>An object with keys of type K and values of type V.
ReturnType<F>The return type of a function type.
TypeScript
type UserUpdate = Partial<Omit<User, "id">>;

8. What does keyof do?#

keyof produces a union of an object type's keys. Combined with generics, it lets you write type-safe property access.

TypeScript
function getProp<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

getProp({ name: "Asha", age: 25 }, "name"); // string
getProp({ name: "Asha", age: 25 }, "email"); // Error
Common mistake

Using as to silence errors. A type assertion tells TypeScript to trust you without checking, so it can hide real bugs. Prefer narrowing.

Key takeaways#

  • Know when to use interface vs type, and unknown vs any.
  • Be comfortable writing generics and using keyof.
  • Use discriminated unions and narrowing instead of type assertions.