Is there a way in Typescript to dynamically type a function which takes 2 arguments by default but should be able to handle these arguments reapeatedly.
// should be allowed
myFunction(paramA, paramB)
myFunction(paramA, paramB, paramA1, paramB1)
myFunction(paramA, paramB, paramA1, paramB1, paramA2, paramB2)
...
// should produce an error
myFunction(paramA, paramB, paramA1)
It is of course possible to package the params into an object and accept an iterable of this object
interface Param { a: string; b: number; };
function myFunction(...params: Param[]);
but I'd like to achieve it without the need for an object
another possibility would be to add method overloads but this limits the amount of parameters to how many overloads I offer and still allows for passing an odd amount of parameters without type error
function myFunction(paramA: string, paramB: number);
function myFunction(paramA: string, paramB: number, paramA1: string, paramB1: number);
function myFunction(paramA: string, paramB: number, paramA1?: string, paramB1?: number);
Is there some trickery to elegantly allow for the wanted behaviour?