TypeScript Concepts
Key remapping — transforming mapped keys
A mapped type can compute output keys using an as clause. Mapping a key to never removes it. Template literal types can generate new string keys; use suitable key constraints so symbol or numeric keys are treated deliberately. Remapping describes an output type and does not implement the runtime transformation. Observed output: 'ready'. 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 Getters<T> = { [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K] };Working Example
Example Snippettypescript
type Getters<T> = { [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K] };const api: Getters<{ label: string }> = { getLabel: () => "ready" };console.log(api.getLabel());