Preparing for a frontend or full-stack interview? If the position involves modern web development, you are almost guaranteed to face TypeScript interview questions. TypeScript has become the standard for writing scalable, robust JavaScript applications, and employers want to know you understand its core features, not just how to append : any to variables.

In this guide, we dive into the most common and tricky TypeScript interview questions you might encounter, along with clear, actionable answers to help you ace your next technical interview on totop.app!

Hero Image

Why TypeScript?

Before jumping into specifics, let's understand why interviewers care about TypeScript. TypeScript is a superset of JavaScript that adds static typing. This helps catch errors at compile-time rather than runtime, improves code readability, and enhances IDE support (autocompletion, refactoring). Understanding the why is just as important as the how.

Beginner to Intermediate Questions

1. What are the key differences between interface and type in TypeScript?

Answer: Both interface and type can describe the shape of an object or a function signature. However, there are subtle differences:

  • Extensibility: Interfaces are better suited for inheritance. They can be extended using the extends keyword. Types use intersections (&) to achieve similar merging.
  • Declaration Merging: Interfaces support declaration merging (typing the same interface multiple times merges them). Types do not.
  • Primitives/Unions/Tuples: Types can represent primitive values, union types (string | number), and tuples. Interfaces are strictly for object shapes.

Pro Tip: Use interface by default for object shapes and type for unions, intersections, and primitive aliases.

2. Can you explain what Generics are and why they are useful?

Answer: Generics allow you to write reusable, type-safe code that works with a variety of data types rather than a single one. It’s like a variable for types.

function identity<T>(arg: T): T {
    return arg;
}
let output1 = identity<string>("myString");
let output2 = identity<number>(100);

Diagram

3. What is a Union Type?

Answer: A union type describes a value that can be one of several types. We use the vertical bar (|) to separate each type.

function printId(id: number | string) {
  console.log(`Your ID is: ${id}`);
}

4. What are Type Guards?

Answer: Type guards are mechanisms that allow you to narrow down the type of an object within a conditional block. TypeScript uses type guards to understand the specific type at runtime. Common type guards include typeof, instanceof, and custom type guard functions using value is Type.

function isNumber(x: any): x is number {
  return typeof x === "number";
}

Illustration (Even the best of us rely on any when things get messy... but try not to do this in an interview!)

Advanced TypeScript Questions

5. What are Utility Types? Can you name a few?

To manipulate types globally without writing from scratch, TypeScript provides several built-in utility types:

  • Partial<T>: Makes all properties in T optional.
  • Required<T>: Makes all properties in T required.
  • Readonly<T>: Makes all properties in T read-only.
  • Pick<T, K>: Creates a type by picking the set of properties K from T.
  • Omit<T, K>: Creates a type by removing properties K from T.

6. What is the any type vs. the unknown type?

  • any: Turns off type checking for heavily dynamic or un-typed scenarios. It can be assigned to anything, and anything can be assigned to it. It destroys the benefits of TypeScript.
  • unknown: It is the type-safe counterpart of any. You can assign anything to unknown, but you cannot assign unknown to anything else (except any and unknown) without a type assertion or type guard. It forces you to check the type before using it.

7. What is a conditional type in TypeScript?

Answer: Conditional types help describe the relationship between types, acting somewhat like an if statement for type definitions. They take the form T extends U ? X : Y.

type NonNullable<T> = T extends null | undefined ? never : T;

8. Explain the never type.

Answer: The never type represents the type of values that never occur. It's the return type for a function that always throws an exception or one that never returns (e.g., an infinite loop). It is useful for exhaustive type checking in switch statements.


Type-Level Programming & Production TypeScript (Questions 9–15)

For senior frontend and full-stack roles, interviewers push past basic interfaces to test your mastery of TypeScript's structural type system and type-level programming:

9. What is the difference between a type annotation (: Type), a type assertion (as Type), and the satisfies operator?

Answer:

  • Type Annotation (const cfg: Config = ...): Validates the object against Config, but widens the variable's inferred type to Config (losing literal autocomplete on specific keys or union branches).
  • Type Assertion (as Config): Tells the compiler to trust you blindly, bypassing type safety and risking runtime TypeError crashes if a required property is missing.
  • The satisfies Operator (const cfg = { ... } satisfies Config): Introduced in TypeScript 4.9+, satisfies validates that the expression matches Config at compile time without widening the underlying literal types—giving you both strict validation and exact property inference!

10. How does conditional type inference (infer) work when building custom utility types?

Answer: The infer keyword inside a conditional type (T extends Pattern<infer U> ? U : never) asks TypeScript to pattern-match against a structure and extract an inner type variable U. For example, extracting the resolved value of a deeply nested Promise:

type UnwrapPromise<T> = T extends Promise<infer U> ? UnwrapPromise<U> : T;
type Result = UnwrapPromise<Promise<Promise<{ id: string }>>>; // { id: string }

11. Why are function parameters contravariant in TypeScript (strictFunctionTypes), and how do you convert a Union into an Intersection?

Answer: Under strictFunctionTypes, function parameter types are contravariant while return types are covariant. That means a callback accepting Animal can safely be passed where a callback accepting Dog is expected, but not vice versa. Advanced type-level challenges use parameter contravariance alongside distributive conditional types to convert a union A | B into an intersection A & B:

type UnionToIntersection<U> =
  (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;

Understanding why U extends any distributes over each union member before infer I collects the contravariant parameter position into an intersection is a hallmark of Staff-level TypeScript fluency.

12. How do Branded (Nominal) Types prevent mixing up primitive IDs in TypeScript's structural type system?

Answer: Because TypeScript is structurally typed, type UserId = string and type OrderId = string are completely interchangeable—passing an orderId into deleteUser(userId: UserId) compiles without error! To enforce compile-time nominal safety with zero runtime overhead, intersect the primitive with a phantom brand symbol: type Brand<K, T> = K & { readonly __brand: T }; type UserId = Brand<string, 'UserId'>;. Now raw strings or OrderId values cannot be passed to deleteUser unless explicitly validated through a smart constructor.

13. How do Discriminated Unions and Exhaustiveness Checking with never prevent unhandled state bugs?

Answer: A discriminated union shares a literal tag property across all members (e.g., type RequestState<T> = { status: 'loading' } | { status: 'success'; data: T } | { status: 'error'; error: Error }). In a switch (state.status) block, assigning the default branch to const _exhaustive: never = state; causes a compile-time error the moment a developer adds a new union variant (such as status: 'idle') without handling it.

14. What are User-Defined Type Guards (x is Type) and Assertion Functions (asserts x is Type)?

Answer: When validating untrusted API payloads at runtime, returning a boolean predicate function isUser(val: unknown): val is User tells the TypeScript control-flow analyzer to narrow val to User inside the if (isUser(data)) branch. Similarly, function assertIsUser(val: unknown): asserts val is User narrows val for all remaining lines in the enclosing scope if the function returns without throwing.

15. How do Template Literal Types and Key Remapping (as) work in Mapped Types?

Answer: TypeScript allows string pattern composition at the type level using backtick template literals combined with Capitalize<T> and mapped key remapping:

type Getters<T> = {
  [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};

This transforms { name: string; age: number } into { getName: () => string; getAge: () => number } automatically, eliminating manual boilerplate across typed event emitters and state stores.


Mastering Your Next Interview with totop.app

Knowing the syntax of TypeScript is one thing, but explaining it clearly and writing it flawlessly under pressure is another. That's where totop.app shines.

Our platform provides hyper-realistic, AI-driven mock interviews that challenge your theoretical knowledge and your practical coding skills. Practice these exact TypeScript questions, get instant, constructive feedback, and build the confidence you need to land your dream job!

Happy coding!


Practice Senior React Engineer Questions Live with AI Mock Interviews

Turn any job description across Engineering, DevOps, Data, Marketing, Sales, Finance, or HR into a personalized test and live voice or text AI mock interview on totop.app, or test your speed right now in the 60-Second Senior React Engineer Blitz.

Play 60s Senior React Engineer Blitz (Free, No Login) | Start 14-Day Free Trial | Browse All Interview Guides