What is the output of `type Flatten = T extends Array ? U : T` when applied as `Flatten`?

TypeScript Professional Hard

TypeScript Professional — Hard

What is the output of `type Flatten = T extends Array ? U : T` when applied as `Flatten`?

Key points

  • The conditional type `T extends Array ? U : T` checks if `T` is an array.
  • If `T` is an array, it returns `U`.
  • If `T` is not an array, it returns `T`.
  • In this case, `T` is not an array, so the output is `string`.

Ready to go further?

Related questions