What if you could change every property in a type with just one simple rule?
Why mapped types are needed in Typescript - The Real Reasons
Imagine you have a list of user settings, and you want to create a new version where every setting is optional or read-only. Doing this by hand means writing out each property again and again.
Manually rewriting each property is slow and boring. It's easy to make mistakes, like forgetting a property or mixing up types. When your settings grow or change, you must update many places, which wastes time and causes bugs.
Mapped types let you create new types by transforming existing ones automatically. You write the rule once, and TypeScript applies it to every property. This saves time, reduces errors, and keeps your code clean and easy to update.
type UserSettingsOptional = {
theme?: string;
notifications?: boolean;
layout?: string;
};type UserSettingsOptional<T> = {
[K in keyof T]?: T[K];
};Mapped types make it easy to create flexible, reusable types that adapt automatically as your data changes.
When building a form, you can quickly create a version of your data where all fields are optional for partial updates, without rewriting every field manually.
Manual type changes are slow and error-prone.
Mapped types automate changes across all properties.
This leads to cleaner, safer, and easier-to-maintain code.