Type vs Interface: TypeScript Interview Question

The interview answer to type vs interface: what only each can do, declaration merging, performance, and the rule to state for a team.

In this chapter

Interview: type or interface?

Type vs interface: common questions

What can an interface do that a type cannot?

Interfaces merge when declared twice with the same name, which libraries use to let you extend their types. Types cannot be reopened.

What can a type do that an interface cannot?

Name unions, tuples, primitives, mapped and conditional types.

More on TypeScript interviews

Keep learning

Overview

chapters · typescript interviews Interview: type or interface? The honest differences: merging, extends vs &, unions, performance and error messages. declaration merging extends vs & index signatures

1. The problem: two files, one silent surprise

Both interface and type give a name to a shape of data. Here two teams each declare a shape with the same name. Left: both use interface. Right: both use type. interface: merges silently No error. Two interfaces with the same name are joined into one. This is called declaration merging. So Cart now has both id and coupon, and nobody was warned. type: refuses to merge Duplicate identifier 'Basket'. A type alias (a name made with type) can point to only one type. A second type with the same name is an error, so the clash is caught at once. Weak answer “They are the same, I just pick one.” Strong answer Lists 4 real differences, then gives a default and a reason.

2. The honest differences

Words used in the table below: union (A | B): a value that is one of several types. tuple: an array with a fixed length, like [string, number]. primitive: a simple value type such as string, number or boolean. mapped / conditional type: a type built by a rule, like a loop or an if. Record<string, unknown>: “an object with any string keys”. unknown means “any value, check before use”. implement: a class promises to have every field of the type. extends: an interface copies all fields of another and adds its own. & (intersection): a type that must match both sides at once. Object shapes Unions, tuples, primitives Mapped / conditional types Declaration merging Conflicts caught on extend Fits Record<string, unknown> Class can implement 'some': a class can implement a type alias only if it is an object type, not a union. extends vs & The one job only interface can do: add fields to someone else’s type (Window, Express Request, a library’s config).

3. Predict it

What is Q? string | number Step 1: & builds an intersection, a type that must match both sides. Step 2: so qty must be a number and also a string. Step 3: no value is both at once. Step 4: TS writes that as never, the empty type that no value fits. So Q is never.

How TypeScript reaches never

Item says qty is The added part says qty is & asks for both at once number & string No value is both, so TS simplifies to

4. Performance and error messages

This matters only in very large codebases. It makes type checking (the compiler checking your code) slower. Worth one sentence in the interview. interface extends is cached TS checks that Sale fits Base once, then remembers the answer by the name Sale. & is re-computed A & B has no saved name, so TS may combine A and B again at each place it is used. Errors show the name Rarely matters Only measurable in large projects with deep extends chains.

5. The model answer

Type or interface: which do you use, and why? Same for Plain object shapes. Either works. type only Unions, tuples, mapped and conditional types. interface only Declaration merging, to augment Window or a library. My default Either default is fine. The signal is that you know why, and you stay consistent.

6. Follow-ups

When is declaration merging a bug, not a feature? When two files reuse a global name by accident. A script file (one with no import or export) shares one global scope: all its names are visible everywhere. Fix: make every file a module, or use type aliases. modules vs scripts Can a class implement a type alias? Yes, if it resolves to an object type. Not a union: “A class can only implement an object type…” Why does an interface not fit Record<string, unknown>? Interfaces can be merged later, so their key set is open. TS will not give them a hidden “any string key” rule (an implicit index signature). Type aliases are closed, so they get one. implicit index signature Do interfaces and types behave differently in emitted JS (the JavaScript that TS outputs)? No. Both are erased: deleted from the output JavaScript. Neither exists at runtime (when the code runs), so instanceof cannot check either.

7. Scorecard

Named declaration merging Said unions need type Explained extends vs & conflicts Knew the index-signature difference Gave a default and a reason

Remember

For plain object shapes, both work. Unions, tuples, mapped and conditional types need type. Pick a default, say why, stay consistent. ! Cheat code type for unions and computed types. interface for merging. extends errors, & gives never. → Go deeper: object types, declaration merging, type performance, 25 quick questions.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.