Given a nested overloaded function, such as innerOverloaded below, what is the best way to call it from a parent overloaded function that has similarly overloaded parameters as the inner one, as in the case with overloadedWithError?
It seems that TypeScript can't figure out that the types are covariant (using the term somewhat loosely here).
function innerOverloaded(foo: true): false;
function innerOverloaded(foo: false): true;
function innerOverloaded(foo: boolean): boolean {
return !foo;
}
function overloadedWithError(foo: boolean): boolean {
return innerOverloaded(foo);
}
function overloadedButUgly(foo: boolean): boolean {
return foo ? innerOverloaded(foo) : innerOverloaded(foo);
}
function overloadedButLessUgly(foo: boolean): boolean {
return innerOverloaded(foo as true);
}