What does the following conditional type produce for T = string | number? type StringOnly = T extends string ? T : never; type Result = StringOnly;

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following conditional type produce for T = string | number? type StringOnly = T extends string ? T : never; type Result = StringOnly;

Key points

  • Conditional types filter unions based on constraints
  • 'number extends string' results in never in this case
  • StringOnly type only includes strings
  • Result type is the filtered string type

Ready to go further?

Related questions