1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
tests/cases/compiler/overloadAssignmentCompat.ts(34,10): error TS2394: Overload signature is not compatible with function implementation.
==== tests/cases/compiler/overloadAssignmentCompat.ts (1 errors) ====
// ok - overload signatures are assignment compatible with their implementation
class Accessor {}
function attr(name: string): string;
function attr(name: string, value: string): Accessor;
function attr(map: any): Accessor;
function attr(nameOrMap: any, value?: string): any {
if (nameOrMap && typeof nameOrMap === "object") {
// handle map case
return new Accessor;
}
else {
// handle string case
return "s";
}
}
// not ok - there's an assignment compat error
function attr2(name: string): string;
function attr2(name: string, value: string): Accessor;
function attr2(map: any): Accessor;
function attr2(nameOrMap: any, value?: string): string {
if (nameOrMap && typeof nameOrMap === "object") {
// handle map case
return "t";
}
else {
// handle string case
return "s";
}
}
// error - signatures are not assignment compatible
function foo():number;
~~~
!!! error TS2394: Overload signature is not compatible with function implementation.
function foo():string { return "a" };
|