In TypeScript, the concept of NonNullable is defined as
type NonNullable<T> = T extends null | undefined ? never : T
For instance,
type ExampleType = NonNullable<string | number | undefined>;
Once evaluated, ExampleType simplifies to
type ExampleType = string | number
How does TypeScript infer ExampleType in this case? One might expect it to result in never, given that string | number | undefined extends null | undefined (isn't that correct?). But why does it give string | number instead?
In connection to this, why doesn't TypeScript use the alternative definition below?
type NonNullable<T> = Exclude<T, null | undefined>