TypeScript Advanced
Generics, conditional types, mapped types, utility types, decorators, namespaces, modules
1What is a generic in TypeScript?
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.
2What is the role of the Partial<T> utility type?
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.
3What is the difference between Pick<T, K> and Omit<T, K>?
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.
How to constrain a generic to certain types?
Which utility type makes all properties required?
+17 interview questions
Other Angular interview topics
TypeScript Basics
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Directives & Pipes
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
HttpClient & API Calls
Basic State Management
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Performance Optimization
Security & Best Practices
Advanced RxJS Patterns
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free