As demonstrated in this example using TypeScript:
type FirstOrSecond<condition, T1, T2> = condition extends never ? T1 : T2
type foo = never extends never ? () => 'hi' : (arg1: never) => 'hi'
type wtf = FirstOrSecond<never, () => 'hi', (arg1: never) => 'hi'>
The generic function FirstOrSecond
assigns never
to the wtf
variable, while the specific definition of foo
assigns () => 'hi'
as the type.
What causes the generic function to behave unexpectedly?