any
seems to both extend and not extend any[]
i.e. it returns both values 1 | 2
:
type Test<T> = T extends any[] ? 1 : 2;
type Result = Test<any>; // 1 | 2
Is this correct? And how could I determine the difference between being passed an any
vs an Array<any>
?
I am trying to use it in the following example and it's causing unexpected results (not sure if the problems are related):
type Push<T, A = []> = [T, ...(A extends any[] ? A : [A])];
type PushTest = Push<5, any>; // [5, ...any[]]
I would expect PushTest to be [5, any]
not [5, ...any[]]
.
Push<5, 6>
works (returning [5, 6]
) and using unknown
also works, but I haven't been able to get any
to work.
This is just part of my experimentation to gain a deeper understanding of TS.
Thank you for any help.