What does the ‘as’ clause in a mapped type key remapping enable? type Example = { [K in keyof T as K extends string ? K : never]: T[K] }

TypeScript Associate Hard

TypeScript Associate — Hard

What does the ‘as’ clause in a mapped type key remapping enable? type Example = { [K in keyof T as K extends string ? K : never]: T[K] }

Key points

  • The 'as' clause filters out non-string keys by remapping them to never
  • It helps maintain type safety by excluding unwanted keys
  • This feature is particularly useful for restricting key types in mapped types

Ready to go further?

Related questions