TypeScript Concepts

Homomorphic mapped types — shape-preserving mapping

A generic mapping directly over keyof T can preserve source property modifiers, and ordinary shape-preserving mappings can retain tuple structure. Explicit modifiers can change readonly or optional status. Not every mapped type is homomorphic: mapping unrelated keys or remapping keys can alter structure. This is a static transformation, not a copy operation. Observed output: '4'. Local example verified with TypeScript 5.8.3, strict checking, ES2022/CommonJS and Node.js 22.16.0; declarations enabled.

Formal Syntax & Structure

typescript syntaxtypescript
type Copy<T> = { [K in keyof T]: T[K] };

Working Example

Example Snippettypescript
type Copy<T> = { [K in keyof T]: T[K] };type Source = { readonly id: number; note?: string };const result: Copy<Source> = { id: 4 };console.log(result.id);
TypeScript Reference