In the following code you notice that the type of Result1
is never
, yet the type of test3
is []
. I can't make sense of this. Why are the results not the same, considering that they are both reading the never
type from MyEvents
?
type EventArgs<EventTypes, K extends keyof EventTypes> =
EventTypes[K] extends never /* CHECK NEVER */
? []
: EventTypes[K] extends any[]
? EventTypes[K]
: [EventTypes[K]];
type foo<T> = T extends never /* CHECK NEVER */ ? [] : [boolean]
type Result1 = foo<MyEvents['anotherEvent']> // HERE, type is `never`
type MyEvents = {
anotherEvent: never // event has no args
}
type Result2 = EventArgs<MyEvents, 'anotherEvent'> // HERE, type is `[]`