Skip to content

Commit ae836eb

Browse files
Merge pull request microsoft#30028 from Microsoft/betterOverloadErrors
Better overload incompatibility errors
2 parents b67f2d6 + d6bb3ee commit ae836eb

29 files changed

+102
-64
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24448,7 +24448,10 @@ namespace ts {
2444824448
const bodySignature = getSignatureFromDeclaration(bodyDeclaration);
2444924449
for (const signature of signatures) {
2445024450
if (!isImplementationCompatibleWithOverload(bodySignature, signature)) {
24451-
error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
24451+
addRelatedInfo(
24452+
error(signature.declaration, Diagnostics.This_overload_signature_is_not_compatible_with_its_implementation_signature),
24453+
createDiagnosticForNode(bodyDeclaration, Diagnostics.The_implementation_signature_is_declared_here)
24454+
);
2445224455
break;
2445324456
}
2445424457
}

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@
14041404
"category": "Error",
14051405
"code": 2393
14061406
},
1407-
"Overload signature is not compatible with function implementation.": {
1407+
"This overload signature is not compatible with its implementation signature.": {
14081408
"category": "Error",
14091409
"code": 2394
14101410
},
@@ -2585,6 +2585,10 @@
25852585
"category": "Error",
25862586
"code": 2749
25872587
},
2588+
"The implementation signature is declared here.": {
2589+
"category": "Error",
2590+
"code": 2750
2591+
},
25882592

25892593
"Import declaration '{0}' is using private name '{1}'.": {
25902594
"category": "Error",

tests/baselines/reference/anyIdenticalToItself.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
tests/cases/compiler/anyIdenticalToItself.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/anyIdenticalToItself.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22
tests/cases/compiler/anyIdenticalToItself.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
33
tests/cases/compiler/anyIdenticalToItself.ts(10,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
44

55

66
==== tests/cases/compiler/anyIdenticalToItself.ts (3 errors) ====
77
function foo(x: any);
88
~~~
9-
!!! error TS2394: Overload signature is not compatible with function implementation.
9+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
10+
!!! related TS2750 tests/cases/compiler/anyIdenticalToItself.ts:3:10: The implementation signature is declared here.
1011
function foo(x: any);
1112
function foo(x: any, y: number) { }
1213

tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/constructorsWithSpecializedSignatures.ts(18,5): error TS2394: Overload signature is not compatible with function implementation.
2-
tests/cases/compiler/constructorsWithSpecializedSignatures.ts(26,5): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/constructorsWithSpecializedSignatures.ts(18,5): error TS2394: This overload signature is not compatible with its implementation signature.
2+
tests/cases/compiler/constructorsWithSpecializedSignatures.ts(26,5): error TS2394: This overload signature is not compatible with its implementation signature.
33

44

55
==== tests/cases/compiler/constructorsWithSpecializedSignatures.ts (2 errors) ====
@@ -22,7 +22,8 @@ tests/cases/compiler/constructorsWithSpecializedSignatures.ts(26,5): error TS239
2222
constructor(x: "hi");
2323
constructor(x: "foo");
2424
~~~~~~~~~~~~~~~~~~~~~~
25-
!!! error TS2394: Overload signature is not compatible with function implementation.
25+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
26+
!!! related TS2750 tests/cases/compiler/constructorsWithSpecializedSignatures.ts:20:5: The implementation signature is declared here.
2627
constructor(x: number);
2728
constructor(x: "hi") { }
2829
}
@@ -32,7 +33,8 @@ tests/cases/compiler/constructorsWithSpecializedSignatures.ts(26,5): error TS239
3233
constructor(x: "hi");
3334
constructor(x: "foo");
3435
~~~~~~~~~~~~~~~~~~~~~~
35-
!!! error TS2394: Overload signature is not compatible with function implementation.
36+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
37+
!!! related TS2750 tests/cases/compiler/constructorsWithSpecializedSignatures.ts:28:5: The implementation signature is declared here.
3638
constructor(x: string);
3739
constructor(x: "hi") { } // error
3840
}

tests/baselines/reference/functionAndInterfaceWithSeparateErrors.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22
tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(6,5): error TS2411: Property 'prop' of type 'number' is not assignable to string index type 'string'.
33

44

55
==== tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts (2 errors) ====
66
function Foo(s: string);
77
~~~
8-
!!! error TS2394: Overload signature is not compatible with function implementation.
8+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
9+
!!! related TS2750 tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts:2:10: The implementation signature is declared here.
910
function Foo(n: number) { }
1011

1112
interface Foo {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22

33

44
==== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts (1 errors) ====
55
function f(x: string): number;
66
~
7-
!!! error TS2394: Overload signature is not compatible with function implementation.
7+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
8+
!!! related TS2750 tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts:2:10: The implementation signature is declared here.
89
function f(x: string): void {
910
return;
1011
}

tests/baselines/reference/functionOverloadErrors.errors.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(75,21): error TS2383
55
tests/cases/conformance/functions/functionOverloadErrors.ts(79,14): error TS2383: Overload signatures must all be exported or non-exported.
66
tests/cases/conformance/functions/functionOverloadErrors.ts(85,18): error TS2384: Overload signatures must all be ambient or non-ambient.
77
tests/cases/conformance/functions/functionOverloadErrors.ts(90,18): error TS2384: Overload signatures must all be ambient or non-ambient.
8-
tests/cases/conformance/functions/functionOverloadErrors.ts(94,10): error TS2394: Overload signature is not compatible with function implementation.
9-
tests/cases/conformance/functions/functionOverloadErrors.ts(99,10): error TS2394: Overload signature is not compatible with function implementation.
10-
tests/cases/conformance/functions/functionOverloadErrors.ts(103,10): error TS2394: Overload signature is not compatible with function implementation.
8+
tests/cases/conformance/functions/functionOverloadErrors.ts(94,10): error TS2394: This overload signature is not compatible with its implementation signature.
9+
tests/cases/conformance/functions/functionOverloadErrors.ts(99,10): error TS2394: This overload signature is not compatible with its implementation signature.
10+
tests/cases/conformance/functions/functionOverloadErrors.ts(103,10): error TS2394: This overload signature is not compatible with its implementation signature.
1111
tests/cases/conformance/functions/functionOverloadErrors.ts(116,19): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
1212

1313

@@ -121,20 +121,23 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(116,19): error TS237
121121
//Function overloads with fewer params than implementation signature
122122
function fewerParams();
123123
~~~~~~~~~~~
124-
!!! error TS2394: Overload signature is not compatible with function implementation.
124+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
125+
!!! related TS2750 tests/cases/conformance/functions/functionOverloadErrors.ts:95:10: The implementation signature is declared here.
125126
function fewerParams(n: string) {
126127
}
127128

128129
//Function implementation whose parameter types are not assignable to all corresponding overload signature parameters
129130
function fn13(n: string);
130131
~~~~
131-
!!! error TS2394: Overload signature is not compatible with function implementation.
132+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
133+
!!! related TS2750 tests/cases/conformance/functions/functionOverloadErrors.ts:100:10: The implementation signature is declared here.
132134
function fn13(n: number) { }
133135

134136
//Function overloads where return types are not all subtype of implementation return type
135137
function fn14(n: string): string;
136138
~~~~
137-
!!! error TS2394: Overload signature is not compatible with function implementation.
139+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
140+
!!! related TS2750 tests/cases/conformance/functions/functionOverloadErrors.ts:104:10: The implementation signature is declared here.
138141
function fn14() {
139142
return 3;
140143
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
tests/cases/compiler/functionOverloads11.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/functionOverloads11.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22

33

44
==== tests/cases/compiler/functionOverloads11.ts (1 errors) ====
55
function foo():number;
66
~~~
7-
!!! error TS2394: Overload signature is not compatible with function implementation.
7+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
8+
!!! related TS2750 tests/cases/compiler/functionOverloads11.ts:2:10: The implementation signature is declared here.
89
function foo():string { return "" }
910

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
tests/cases/compiler/functionOverloads17.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/functionOverloads17.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22

33

44
==== tests/cases/compiler/functionOverloads17.ts (1 errors) ====
55
function foo():{a:number;}
66
~~~
7-
!!! error TS2394: Overload signature is not compatible with function implementation.
7+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
8+
!!! related TS2750 tests/cases/compiler/functionOverloads17.ts:2:10: The implementation signature is declared here.
89
function foo():{a:string;} { return {a:""} }
910

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
tests/cases/compiler/functionOverloads18.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
1+
tests/cases/compiler/functionOverloads18.ts(1,10): error TS2394: This overload signature is not compatible with its implementation signature.
22

33

44
==== tests/cases/compiler/functionOverloads18.ts (1 errors) ====
55
function foo(bar:{a:number;});
66
~~~
7-
!!! error TS2394: Overload signature is not compatible with function implementation.
7+
!!! error TS2394: This overload signature is not compatible with its implementation signature.
8+
!!! related TS2750 tests/cases/compiler/functionOverloads18.ts:2:10: The implementation signature is declared here.
89
function foo(bar:{a:string;}) { return {a:""} }
910

0 commit comments

Comments
 (0)