Key Remapping with as in Mapped Types
Rename keys during type transformation.
Key Remapping with as in Mapped Types is a free TypeScript Academy lesson on CoddyKit — lesson 4 of 4. 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 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
Basic Key Remapping
type Prefixed<T> = {
[K in keyof T as `prefix_${string & K}`]: T[K]
};
type P = Prefixed<{ name: string }>;
// { prefix_name: string }Filtering Keys with never
type OnlyStrings<T> = {
[K in keyof T as T[K] extends string ? K : never]: T[K]
};Generating Getter Names
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]
};
type UserGetters = Getters<{ name: string; age: number }>;
// { getName: () => string; getAge: () => number }Generating Setter Names
type Setters<T> = {
[K in keyof T as `set${Capitalize<string & K>}`]: (val: T[K]) => void
};Invert a Record Type
type Invert<T extends Record<string, string>> = {
[K in keyof T as T[K]]: K
};Conditional Key Remapping
type MethodKeys<T> = {
[K in keyof T as T[K] extends Function ? K : never]: T[K]
};Combining with Template Literals
type Namespaced<T, NS extends string> = {
[K in keyof T as `${NS}::${string & K}`]: T[K]
};Mapping Symbol Keys
Practical: FormData Type
type FormFields<T> = {
[K in keyof T as K extends string ? K : never]: string
};Combining as with Conditional Types
Quick Check
Recap
Frequently asked questions
Is the “Key Remapping with as in Mapped Types” lesson free?
Yes — the full text of “Key Remapping with as in Mapped Types” is free to read here on the web, and the TypeScript Academy course includes 4 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 “Key Remapping with as in Mapped Types”?
Rename keys during type transformation. 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 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Key Remapping with as in Mapped Types” 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: Transforming Object Types
- Modifiers in Mapped Types: readonly and ?
- Template Literal Types: String Patterns
- Key Remapping with as in Mapped Types