01
Overview
Mapped types iterate over keys. [K in keyof T] transforms each property. Modifiers: +readonly, -readonly, +?, -?. Key remapping with as. Combine with conditional types.
bash
type Readonly<T>={readonly [K in keyof T]:T[K]};
type Partial<T>={[K in keyof T]?:T[K]};
type Mutable<T>={-readonly [K in keyof T]:T[K]};
type Getters<T>={[K in keyof T as `get${Capitalize<string&K>}`]:()=>T[K]};02
Best Practices
Use mapped types for bulk property transformations. Key remapping (as) for renaming. Modifiers (+/-) for readonly/optional. Combine with conditional types. Keep readable. Document complex mappings.
Ready to try Mapped Types?
Visit the official site for the latest version and full documentation.
Visit Mapped Types