Mapped types with +/-readonly and +/-?
Explore mapped types and modifiers (+/-readonly, +/-optional) to create flexible variations of object shapes.
Intro
Goal: Learn mapped types with modifiers to alter object properties systematically. They let you create readonly, optional, or required versions of types.
Basic mapped type
A mapped type iterates keys and reuses property types. This is the foundation for transformations.
type Options = { a: string; b: number }
type Clone<T> = { [K in keyof T]: T[K] }
type Copy = Clone<Options> // { a: string; b: number }All lessons in this course
- Mapped types with +/-readonly and +/-?
- Key remapping & template literal types
- String-pattern typing (route params, event names)