Typescript: Get the type of the last parameter of a function type

后端 未结 4 838
花落未央
花落未央 2021-01-05 16:32

Assume I have a function type, e.g.

type somefntype = (a: number, b: string, c: boolean) => void

I need the type of that function types

4条回答
  •  滥情空心
    2021-01-05 17:06

    As of TypeScript 4.0 with variadic tuple support, it's also possible to use the following to get the last type in a tuple type:

    type LastType]> = T extends [...infer A, infer L] ? L : never;
    

提交回复
热议问题