100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

TypeScript Mapped Types Cheat Sheet

TypeScript Mapped Types Cheat Sheet

Covers the [K in keyof T] syntax, key remapping with as, readonly/optional modifiers, and template literal key patterns.

1 PageAdvancedApr 6, 2026

Basic Mapped Type Syntax

Iterate over a union of keys and build a new object type from them.

typescript
type User = { id: number; name: string; email: string };type ReadonlyUser = { readonly [K in keyof User]: User[K] };type PartialUser  = { [K in keyof User]?: User[K] };type Stringify<T> = { [K in keyof T]: string };type UserStrings = Stringify<User>;// { id: string; name: string; email: string }

Adding & Removing Modifiers

Prefix with `+`/`-` to explicitly add or strip `readonly`/`?`.

typescript
type Mutable<T> = { -readonly [K in keyof T]: T[K] };type Required2<T> = { [K in keyof T]-?: T[K] };type Optional<T>  = { [K in keyof T]+?: T[K] };interface Config {    readonly host: string;    port?: number;}type WritableConfig = Mutable<Config>;   // host is no longer readonlytype FullConfig = Required2<Config>;      // port is no longer optional

Key Remapping with `as`

TS 4.1+ lets you transform key names during mapping, or filter keys out entirely.

typescript
type Getters<T> = {    [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]};interface Person { name: string; age: number }type PersonGetters = Getters<Person>;// { getName: () => string; getAge: () => number }// Filter out keys by mapping them to `never`:type OmitByType<T, V> = {    [K in keyof T as T[K] extends V ? never : K]: T[K]};type NonStringProps = OmitByType<Person, string>; // { age: number }

Mapped Type Syntax Reference

Building blocks for constructing mapped types.

  • [K in keyof T]- iterates every key of T, K bound to each key
  • as- remaps the resulting key name (TS 4.1+); map to never to drop a key
  • readonly / -readonly- add or strip the readonly modifier
  • ? / -?- add or strip optionality
  • T[K]- indexed access to get the value type for key K
  • keyof T- union of all property names of T, the usual source for K
Pro Tip

Combine key remapping with template literal types (e.g. `on${Capitalize<K>}`) to auto-generate event-handler-shaped types from a props interface — this is exactly how libraries type their `onX` callback props.

Was this cheat sheet helpful?

Explore Topics

#TypeScriptMappedTypes#TypeScriptMappedTypesCheatSheet#Programming#Advanced#BasicMappedTypeSyntax#AddingRemovingModifiers#KeyRemappingWithAs#MappedTypeSyntaxReference#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet