I have a function in Typescript with overloads as follows:
function test(atts?: {[key: string]: string}, ...children: string[]): void;
function test(atts?: {[key: string]: string}): void;
function test(...children: string[]): void; //Overload 3
function test(): void;
function test(arg1?: {[key: string]: string} | string[], ...arg2: string[]) {
console.log(arg1, arg2)
}
However, I keep being told that overload 3 is not compatible with it's implementation signature. How do I fix this error?
I've looked at other answers, but am still struggling to make this work. I think it has something to do with arg2 being potentially undefined, which makes it incompatible with the third overload. But rest parameters can't be undefined, so I'm not sure how to implement this logic if that's the case.