We have some code snippets for you to review:
export type actions = {
abort: () => void;
back: () => void;
next: () => void;
resume: () => void;
};
class Sabar {
public use<T1>(fn: (arg1: T1, ctx: object, actions: actions) => void) :void;
public use<T1, T2>(fn: (arg1: T1, arg2: T2, ctx: object, actions: actions) => void) :void;
public use<T1, T2, T3>(fn: (arg1: T1, arg2: T2, arg3: T3, ctx: object, actions: actions) => void) :void;
public use<T1, T2, T3, T4>(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, ctx: object, actions: actions) => void) :void;
public use(fn: Function) :void {
// ....
}
}
const test = new Sabar();
test.use((first, second, third) =>) {} // indicates `second` as an object and `third` as actions
test.use((first, second, third, forth) =>) {}); // indicates `first`, `second`, `third`, and `forth` as any
use
function always has two trailing parameters ctx
and actions
. The initial parameters can vary in length.
The issue at hand is:
- When providing a function with three parameters, TypeScript could indicate the correct type information.
- However, when the provided function has four, five, or more parameters, all these parameters will be indicated as type
any
.
I have searched extensively online for a solution without success. I hope someone can assist me with this matter.
Thank you.