Can generics be leveraged with mapped types to map method types?
For instance, is it feasible to construct a mapped type that adds a first argument of type number
to each method?
Here's an example in pseudo code (though it won't run):
interface Method<TS extends any[], R> {
(...args: TS): R;
}
interface NumberedMethod<TS extends any[], R> {
(n: number, ...args: TS): R;
}
type Numbered<T> = {
// ERROR! Unable to use generics here??
<TS extends any[], R>[K in keyof T]: T[K] extends NumberedMethod<TS, R>? T[K]: T[K] extends Method<TS, R>: NumberedMethod<TS, R>: never;
};
Is there a way to achieve this?