Home > Net >  Defining dynamic function parameters in Typescript
Defining dynamic function parameters in Typescript

Time:01-28

Given this:

type params = Parameters<(x: string, y:number)=>void>

In the pseudo code below how does one make fn to be (x: string, y:number)=>void, but using the params type?

type fn = (...params)=>void // type should be (x: string, y:number)=>void

CodePudding user response:

type fn = (...p: params)=>void

should work. Type the rest parameter with type params.

Playground

  •  Tags:  
  • Related