I was curious to see what would happen when a type was checked if it was void
, and I found the result interesting. It seems that when the input is any
, a union is returned. Can someone shed some light on why this occurs?
type test<T> = T extends void ? void extends T ? 1 : 0 : 0;
type v1 = test<any>; // 1 | 0
type v2 = test<unknown>; // 0
type v3 = test<undefined>; // 0
type v4 = test<null>; // 0
type v5 = test<never>; // never
type v6 = test<void>; // 1
type v7 = test<boolean>; // 0
type v8 = test<string>; // 0
type v9 = test<number>; // 0
type v10 = test<'void'>; // 0
type v11 = test<{}>; // 0