What does the following mapped type key remapping do? type Getters = { [K in keyof T as `get${Capitalize}`]: () => T[K] };

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following mapped type key remapping do? type Getters = { [K in keyof T as `get${Capitalize}`]: () => T[K] };

Key points

  • The remapping adds 'get' before each property name and capitalizes the first letter.
  • This technique is commonly used to generate getter methods for object properties.
  • The resulting type allows access to the values of T through getter functions.

Ready to go further?

Related questions