I have a possibly weird situation that I'm trying to model with typescript.
I have a bunch of functions with the following format
type State = { something: any }
type InitialFn = (state: State, ...args: string[]) => void
I would like to be able to create a type that represents InitialFn
with the first argument removed. Something like
// this doesn't work, as F is unused, and args doesn't correspond to the previous arguments
type PostTransformationFn<F extends InitialFn> = (...args: string[]) => void
Is this possible?
I think you can do that in a more generic way:
type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
and then:
type PostTransformationFn<F extends InitialFn> = OmitFirstArg<F>;
PG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With