2

I got this type from the TS handbook:

type ToArray<Type> = Type extends any ? Type[] : never;

If you evaluate ToArray<string & number>, you get never;

However, if you evaluate type Thing = (string & number) extends any ? never[] : never;, Thing ends up as type never[].

Why?

I've also tried writing out some more examples and none if it seems to help me understand:

type Thing = string & number; // type never
type OtherThing = Thing extends any ? Thing[] : never; // type never[]
type OtherOtherThing = ToArray<Thing>; // type never
D.J. Price
  • 21
  • 2
  • ① You don't need to write `string & number` to see this, you can just use `never` directly. ② The issue is that `ToArray` is a [distributive conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types), and `never` is considered "the empty union". See the other questions/answers for more info. – jcalz Aug 01 '23 at 21:11

0 Answers0