While experimenting around with readonly function parameters, I stumbled across some strange behaviour.
type Test1 = Parameters<(...args: [string] | [number]) => void>;
// Test1 is [string] | [number] as expected
type Test2 = Parameters<(...args: Readonly<[string] | [number]>) => void>;
// Test2 is never
While there is not really a point in using readonly tuples for spread function parameters, so this problem can be solved easily, I would still like to understand what is causing this.
Boiling it down to a simple example:
type Test3 = ((...args: Readonly<[string] | [number]>) => void) extends (...args: infer P) => any ? true : false;
// Test3 is false
type Test4 = ((...args: Readonly<[string] | [number]>) => void) extends (...args: any) => any ? true : false;
// Test4 is true
So far I was under the assumption that infer P
would be equivalent to any
, except that it stores the inferred type in P
. That does not seem to be the case. How can this behaviour be explained?