25 TypeScript Interview Questions with Answers

Twenty-five quick TypeScript interview questions with short answers: any vs unknown, never, generics, utility types, narrowing and tsconfig.

In this chapter

Interview: 25 quick questions

More on TypeScript interviews

Keep learning

Overview

chapters · typescript interviews Interview: 25 quick questions Rapid-fire answers on inference, variance, never, satisfies, overloads and the compiler. compiler & config

1. How to use this page

Read the question, answer out loud, then open it. First bullet is the one-liner to lead with. per answer 1 line then one example Everything you know about never, in no order. One-line definition, one tiny example, one use case. Stop.

2. Core types

any versus unknown? top types Both accept any value. unknown makes you narrow first (check the type with typeof, etc.) before use. any fits into every type and turns off checking everywhere the value goes next. In the example, u could hold a number or null, so it does not fit a string variable until you check it. Type 'unknown' is not assignable to type 'string'. What is never, and where does it show up? bottom type The empty type: no value has it. It fits into (is assignable to) every other type. Used for exhaustiveness checks and to filter unions. string & number Exclude<'a' | 'b', 'a' | 'b'> What is structural typing? type system Compatibility is by shape, not by name. Any object with the required properties fits, extra ones included. Exception: an object written directly in the assignment (a fresh object literal) gets an extra check. Unknown keys like y are an error there. not a string Why are method parameters checked loosely? Methods written as m(a: Animal): void stay bivariant (checked in both directions, so either way passes), even under strict. Prefer property syntax for callbacks you want checked. How do overloads work? Several call signatures, then one implementation signature. Callers only see the overloads, never the implementation. A union argument fails if no single overload accepts it. In the example, string | number fits neither the string-only nor the number-only overload, so line 4 fails. The implementation on line 3 is hidden from callers. No overload matches this call. Abstract class versus interface? Abstract classes can ship shared methods and fields. A class extends one class but implements many interfaces. When is a generic a smell? When the type parameter appears only once. A good type parameter relates two or more positions.

5. Type-level

What does keyof typeof obj give you? Result: a union of the object’s property names. 'latte' | 'mocha' What is infer? conditional types A placeholder inside extends that captures part of a matched type. Only valid in the extends part of a conditional type (T extends X ? A : B). ReturnType, Parameters and Awaited are built with it. What is a distributive conditional type? A conditional type (T extends X ? A : B) on a naked type parameter (plain T, not wrapped like [T]) runs once per union member. ToArray<string | number> gives string[] | number[]. Wrap in [T] extends [X] to stop it. Gotcha: never is an empty union, so there is nothing to run on, and the result is never. T extends any ? T[] : never string[] | number[] [T] extends [any] ? T[] : never (string | number)[] IsNever<never> (naked T) not true: never is an empty union, so the check never runs What is declaration merging? Same-named interfaces (and namespaces) combine into one. Used to augment globals like Window or library types.

6. Compiler and config

What does strict turn on? A family of flags: noImplicitAny, strictNullChecks, strictFunctionTypes and more. Also strictPropertyInitialization, strictBindCallApply, useUnknownInCatchVariables, alwaysStrict, noImplicitThis. New flags join strict over time, so upgrades can surface new errors. Two flags worth adding beyond strict? noUncheckedIndexedAccess: arr[0] and record[key] include undefined. exactOptionalPropertyTypes: theme?: X no longer accepts explicit undefined. string | undefined 'first' is possibly 'undefined'. What is isolatedModules for? A tsconfig setting. It ensures each file can be compiled alone, without type info from others. That is how esbuild, swc and Babel work. whole program: checks types esbuild / swc one file at a time: strips types Does TypeScript change runtime behaviour? Exceptions emit code: enums, namespaces, parameter properties, legacy decorators. So no type checks happen at runtime.

7. Self-check

Led every answer with one line Gave a code example for never and satisfies Explained variance with a callback Knew distributive conditionals and the [T] trick Named three flags inside strict Said what isolatedModules protects

Remember

Shapes, not names, decide compatibility. satisfies checks without widening. Naked type parameters distribute over unions. ! Cheat code One line, one example, one use case. unknown over any. satisfies over as. → Go deeper: any, unknown and never, distributive conditional types, tsconfig, the interview format.

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.