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. This is 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, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 3 lessons in total.
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.
Learn TypeScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 101
- Lessons
- 352
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. 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. The TypeScript Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
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)