Why TypeScript is a Must-Have for the Modern Developer?
\nIf 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.
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\n1. Basics: Types, Interfaces, and the Difference Between Them
\nThe first block of questions is fundamental. The interviewer wants to make sure you don't confuse type and interface.
When to use type, and when to use interface?
\nA 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
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};\nImportant: Never say "interface is better because it's faster." The performance difference is microscopic. The main thing is semantics.
\n\n2. Generics: How Not to Embarrass Yourself in an Interview
\nThe 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.
\nWriting a generic function
\nfunction 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\nNow let's make it more complex — constrain the generic with extends:
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\nThis pattern appears in every other React + TypeScript project. Be sure to practice writing TypeScript generics in your own projects.
\n\n3. Utility Types: Your Secret Arsenal
\nKnowledge 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?"
\nTop 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
An example often given in interviews:
\ninterface 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