Similar to this quesiton: how to reference all parameters except first in typescript
But here, I Want to get all parameters except the last one.
The accepted answer over there did not work in this use case.
Is there a way to do that?
CodePudding user response:
You can use a conditional type and spread the inferred initial parameters:
type InitialParameters<F extends (...args: any) => any> =
Parameters<F> extends [...infer P, any] ? P : never
const f = (str: string, n: number, b: boolean) => {}
type Test = InitialParameters<typeof f>
// [str: string, n: number]
CodePudding user response:
First,
reverse()
and
function aa(a1,...rest){
console.log(a1,"",rest);
}