TSadvancedts-evergreen

Mapped types

Build types from other types.

A mapped type walks the keys of an existing type and produces a new one — the machinery behind Partial, Readonly, and Record, and the place to reach when no built-in utility fits.

Readonly<T> by hand

TSintro
Press Run to execute

The output keys: x,y / values: 3 shows the data survives the mapping intact — MyReadonly<T> only adds the readonly modifier, it never touches the runtime shape or values. The compile-time guard (assigning p.x would error) is invisible at runtime, which is exactly why mapped types cost nothing.