Angular

TypeScript Advanced

Generics, conditional types, mapped types, utility types, decorators, namespaces, modules

20 interview questionsยท
Junior
1

What is a generic in TypeScript?

Answer

A generic allows creating reusable components that work with multiple types rather than a single one. Generics use type parameters (like T) to represent any type. This enables writing type-safe code without sacrificing flexibility, for example a function that manipulates arrays of any type while preserving type information.

2

What is the role of the Partial<T> utility type?

Answer

Partial<T> transforms all properties of a type T into optional properties. This is particularly useful for update functions where only certain fields need to be modified. For example, to update a user, it's possible to provide only the name without having to specify all other fields. TypeScript ensures that only existing properties can be passed.

3

What is the difference between Pick<T, K> and Omit<T, K>?

Answer

Pick<T, K> selects only properties K from a type T, creating a new type with only those properties. Conversely, Omit<T, K> excludes properties K from a type T, creating a new type with all properties except those specified. Pick is useful for creating partial views with necessary fields, while Omit is practical for creating types without certain sensitive fields like passwords.

4

How to constrain a generic to certain types?

5

Which utility type makes all properties required?

+17 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free