I'm trying to remove the first argument from a function that has a generic argument: I would like something like this:
type GenericFunc = <T extends string | number>(c: any, p: T) => T;
type GenericFuncWithoutFirst = OmitFirstArg<GenericFunc> // = <T extends string | number>(p: T) => T;
I've found this related post: Typescript remove first argument from a function
Which suggests:
type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
But this seems to remove the generic type inference when calling the function. I've made a demo of this in typescript playground
Any help solving this would be much appreciated.
(p: P) => P` fixes it, although then you get warnings that `infer P` and `infer R` aren't used. It seems like the issue could be related to the lack of generics in the definition of `RemoveFirstArgument`, but the details aren't clear to me.
– Ryan Pattillo Jul 21 '22 at 20:29