I have a type:
type Action<I extends unknown[], O> = (...args: I) => Promise<O>;
and some test cases:
// should be [boolean, string]
type TestInput = Input<Action<[boolean, string], number>>;
// should be number
type TestOutput = Output<Action<[boolean, string], number>>;
I wrote the Input
type using unknown
for O
and it works:
type Input<A> = A extends Action<infer I, unknown> ? I : never;
then I wrote the Output
type using unknown[]
for I
:
type Output<A> = A extends Action<unknown[], infer O> ? O : never;
and it doesn't works, the TestOutput
is never
.
But when I changed unknown[]
to any[]
it works:
type Output<A> = A extends Action<any[], infer O> ? O : never;
Can anyone explain why?
P.S. I also wrote this test:
type Test = [boolean, string] extends unknown[] ? true : false;
and the Test
is true
, so I don't understand why the Output
with unknown[]
for I
is not works.