Mapped types with +/-readonly and +/-?
Explore mapped types and modifiers (+/-readonly, +/-optional) to create flexible variations of object shapes.
Mapped types with +/-readonly and +/-? is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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 }Add readonly
Use +readonly to force immutability. Every property becomes readonly.
type ReadonlyT<T> = { [K in keyof T]+readonly: T[K] }
interface User { id: number; name: string }
type Locked = ReadonlyT<User> // all props readonlyRemove readonly
Use -readonly to strip immutability and restore mutability.
type Mutable<T> = { [K in keyof T]-readonly: T[K] }
type Editable = Mutable<Locked> // props writable againAdd optional
? after property marks it optional. Useful for config updates.
type PartialT<T> = { [K in keyof T]?: T[K] }
interface Settings { dark: boolean; lang: string }
type Maybe = PartialT<Settings> // props optionalRemove optional
Use -? to remove optionality and enforce presence of properties.
type RequiredT<T> = { [K in keyof T]-?: T[K] }
type Strict = RequiredT<Maybe> // props required againRemove readonly check
Quick check: Which mapped type syntax removes readonly from properties?
Recap
Recap: Mapped types let you apply transformations across properties: +/-readonly, +/-? for mutability and optionality. They are the basis for Partial, Required, Readonly.
Frequently asked questions
Is the “Mapped types with +/-readonly and +/-?” lesson free?
Yes — the full text of “Mapped types with +/-readonly and +/-?” is free to read here on the web, and the TypeScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Mapped types with +/-readonly and +/-?”?
Explore mapped types and modifiers (+/-readonly, +/-optional) to create flexible variations of object shapes. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Mapped types with +/-readonly and +/-?” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Mapped types with +/-readonly and +/-?
- Key remapping & template literal types
- String-pattern typing (route params, event names)