What does the following TypeScript produce? type Flatten = T extends Array ? U : T; type A = Flatten; type B = Flatten;

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following TypeScript produce? type Flatten = T extends Array ? U : T; type A = Flatten; type B = Flatten;

Key points

  • The Flatten type checks if T is an array and assigns U if true
  • A and B are both assigned the Flatten type
  • A is a string because it is not an array
  • B is a number because it is not an array

Ready to go further?

Related questions