TypeScript · Senior · Question 42 of 75

What is a homomorphic mapped type, and what does it preserve?

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.

Further reading

Problem with a question

TypeScript · Senior · question 42

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz