I have a shared function that accepts a callback, which in turn accepts any number and type of arguments. How can I make it, so TS just accepts anything as the callback's argument?
the callback can be (true, 'test', 1) => {...}
, as well as ({a:'foo', b:true}) => {...}
, or () => {...}
My first try way:
type F = (args?: any) => Promise<...>
But this accepts one argument. I thought about:
...args: any[]
, but this requires an array.
Typing the callback as any
is my last resort, but it's not the proper solution here.
CodePudding user response:
This is fine;
const myFunc = (...args: any) => {}