What does the following generic function demonstrate about TypeScript’s ‘infer in conditional return types’? type Unbox = T extends { value: infer V } ? V : never; type Result = Unbox;

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following generic function demonstrate about TypeScript’s ‘infer in conditional return types’? type Unbox = T extends { value: infer V } ? V : never; type Result = Unbox;

Key points

  • 'infer' in conditional return types extracts specific types from matched shapes
  • Unbox function returns the type of the 'value' property
  • Result is determined by the type inferred from the conditional check

Ready to go further?

Related questions