https://bigfrontend.dev/typescript/Parameters
For function type T, Parameters<T> returns a tuple type from the types of its parameters.
Please implement MyParameters<T> by yourself.
type Foo = (a: string, b: number, c: boolean) => string;
type A = MyParameters<Foo>; // [a:string, b: number, c:boolean]
type B = A[0]; // string
type C = MyParameters<{ a: string }>; // Errortype MyParameters<T extends Function> = T extends (...args: infer A) => any
? A
: never;-
In the
extendsclause of a conditional type, we can useinferkeyword to introduce a new type to be inferred. This inferred type can then be referenced in the true branch of the conditional type. For instance, withinferwe can extract the return type of a function type:type ReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
-
(...arg: any[]) => anyis a function type expression which is used to define types for functions.