TypeScript · Senior · Question 42 of 75
What is a homomorphic mapped type, and what does it preserve?
- ✓Correct answer: A
{ [K in keyof T]: ... }type that preservesT's modifiers - 2A type that maps identical values of different objects
- 3A type in which all properties have the same value type
Explanation
When a mapped type iterates over keyof T directly, TS carries over the property modifiers of T. That's why Partial<Readonly<T>> stays readonly. When iterating over an arbitrary union of keys (K in 'a' | 'b'), modifiers aren't preserved.