I have a type that omits specified fields in functions parameter object like this:
type OmitFields<F, K extends string> = F extends (props: infer P) => infer R ? (props: Omit<P, K>) => R : never;
And use it like:
type Omitted = OmitFields<typeof functionWithObjectParam, 'first' | 'second'>
How can I make type parameter K be aware of type that props object gets inferred as, and restrict correct strings to its keys?
I think you want something like:
Here
Fis constrained to be a function that takes one argument. AndKis constrained to the keys of that argument.Then you can reconstruct the function type without any fancy
inferstuff.This seems to do what you want:
Playground