TypeScript: Complete Guide to Interview Preparation

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Why TypeScript is a Must-Have for the Modern Developer?

\n

If you opened this article, you already know that TypeScript is not just a "superset of JavaScript," but a full-fledged tool that saves nerve cells and production servers. In 2025, knowledge of TypeScript is tested in almost 80% of middle+ level job vacancies. And it's not about writing const a: number = 5. Interviewers want to see an understanding of the type system, generics, and the ability to design safe architecture.

\n

In this article, we will break down the most common TypeScript interview questions that are actually asked at top companies. You will get not only theory but also TypeScript code examples that you can immediately use in pet projects. Let's go!

\n\n

1. Basics: Types, Interfaces, and the Difference Between Them

\n

The first block of questions is fundamental. The interviewer wants to make sure you don't confuse type and interface.

\n

When to use type, and when to use interface?

\n

A classic question. Remember this simple rule:

\n
    \n
  • Interface — for objects that can be extended (declaration merging). Use for APIs, DTOs, component props.
  • \n
  • Type — for unions, intersections, primitives, and tuples.
  • \n
\n

Example from a real interview:

\n
// Interface — extendable\ninterface User {\n    id: number;\n    name: string;\n}\n\ninterface AdminUser extends User {\n    role: 'admin';\n}\n\n// Type — union\ntype Status = 'active' | 'inactive' | 'banned';\ntype ApiResponse<T> = {\n    data: T;\n    error?: string;\n};
\n

Important: Never say "interface is better because it's faster." The performance difference is microscopic. The main thing is semantics.

\n\n

2. Generics: How Not to Embarrass Yourself in an Interview

\n

The topic of generics in TypeScript is a favorite pain point for juniors. Interviewers love to ask you to write a function that takes an array and returns the first element with the correct type.

\n

Writing a generic function

\n
function getFirst<T>(arr: T[]): T | undefined {\n    return arr[0];\n}\n\nconst num = getFirst([1, 2, 3]); // number\nconst str = getFirst(['a', 'b']); // string
\n

Now let's make it more complex — constrain the generic with extends:

\n
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {\n    return obj[key];\n}\n\nconst user = { name: 'Alice', age: 30 };\ngetProperty(user, 'name'); // OK: string\ngetProperty(user, 'email'); // Error: 'email' is not in keyof
\n

This pattern appears in every other React + TypeScript project. Be sure to practice writing TypeScript generics in your own projects.

\n\n

3. Utility Types: Your Secret Arsenal

\n

Knowledge of built-in utility types is a sign of professionalism. An interviewer might ask: "How do you make all fields optional?" or "How do you select only part of an interface?"

\n

Top 5 utility types you need to know

\n
    \n
  • Partial<T> — all fields become optional;
  • \n
  • Required<T> — all fields are required;
  • \n
  • Pick<T, K> — select only the specified keys;
  • \n
  • Omit<T, K> — exclude the specified keys;
  • \n
  • Record<K, V> — creates an object type with keys K and values V.
  • \n
\n

An example often given in interviews:

\n
interface Todo {\n    title: string;\n    description: string;\n    completed: boolean;\n    createdAt: Date;\n}\n\n// Update only part of Todo\nfunction updateTodo(todo: Todo, fieldsToUpdate: Partial<Todo>) {\n    return { ...todo, ...fieldsToUpdate };\n}\n\n// Create a dictionary\nconst                

Blogs

Book Recommendations