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
Here is yet a another solution which is a slight modification of jcalz answer to make it more generic using some recursive conditional types:
type Head = T extends [any, ...any[]] ? T[0] : never;
type Tail =
((...t: T) => any) extends ((_: any, ...tail: infer U) => any)
? U
: [];
type HasTail = T extends ([] | [any]) ? false : true;
type Last = {
0: Last>
1: Head
}[
HasTail extends true ? 0 : 1
];
type LastType = Last>; // boolean
It might be interesting to consider replacing any
with unknown
as well.