Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exclude specify index from Parameter type of function

function fun1(a:number, b:string, c:()=>void)
{

}


function fun2(...args:Parameters<typeof fun1>)
{

}

I want exclude a specific index of fun1‘s parameters from function fun2‘s parameter types.

Basically the result should be:

function fun2(b:string, c:()=>void)
{

}

I tried using Omit<Parameters<typeof this._call>, "0"> but it doesn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can declare a Tail type that drops the first element:

type Tail<T extends readonly unknown[]> =
  T extends [unknown, ...infer Rest] ? Rest : never

and use it like this:

function fun2(...args: Tail<Parameters<typeof fun1>>) {}
// function fun2(b: string, c: () => void): void

TypeScript playground

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading