Skip to content

Commit b805037

Browse files
committed
Improved error messages
1 parent 74536cc commit b805037

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,10 @@ module ts {
14211421
else if (links.type === resolvingType) {
14221422
links.type = anyType;
14231423
if (compilerOptions.noImplicitAny) {
1424-
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_type_inference_encountered_a_circularity, symbolToString(symbol));
1424+
var diagnostic = (<VariableDeclaration>symbol.valueDeclaration).type ?
1425+
Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation :
1426+
Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer;
1427+
error(symbol.valueDeclaration, diagnostic, symbolToString(symbol));
14251428
}
14261429
}
14271430
return links.type;
@@ -1494,7 +1497,7 @@ module ts {
14941497
links.type = anyType;
14951498
if (compilerOptions.noImplicitAny) {
14961499
var getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
1497-
error(getter, Diagnostics._0_implicitly_has_type_any_because_type_inference_encountered_a_circularity, symbolToString(symbol));
1500+
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
14981501
}
14991502
}
15001503
}
@@ -2046,10 +2049,10 @@ module ts {
20462049
if (compilerOptions.noImplicitAny) {
20472050
var declaration = <Declaration>signature.declaration;
20482051
if (declaration.name) {
2049-
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_type_inference_encountered_a_circularity, identifierToString(declaration.name));
2052+
error(declaration.name, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, identifierToString(declaration.name));
20502053
}
20512054
else {
2052-
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_type_inference_encountered_a_circularity);
2055+
error(declaration, Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
20532056
}
20542057
}
20552058
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,10 @@ module ts {
390390
Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
391391
Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
392392
Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
393-
_0_implicitly_has_type_any_because_type_inference_encountered_a_circularity: { code: 7021, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because type inference encountered a circularity." },
394-
_0_implicitly_has_return_type_any_because_type_inference_encountered_a_circularity: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because type inference encountered a circularity." },
395-
Function_implicitly_has_return_type_any_because_type_inference_encountered_a_circularity: { code: 7023, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because type inference encountered a circularity." },
393+
_0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 7021, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation." },
394+
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
395+
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
396+
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
396397
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
397398
};
398399
}

src/compiler/diagnosticMessages.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,18 +1557,22 @@
15571557
"category": "Error",
15581558
"code": 7020
15591559
},
1560-
"'{0}' implicitly has type 'any' because type inference encountered a circularity.": {
1560+
"'{0}' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.": {
15611561
"category": "Error",
15621562
"code": 7021
15631563
},
1564-
"'{0}' implicitly has return type 'any' because type inference encountered a circularity.": {
1564+
"'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": {
15651565
"category": "Error",
15661566
"code": 7022
15671567
},
1568-
"Function implicitly has return type 'any' because type inference encountered a circularity.": {
1568+
"'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.": {
15691569
"category": "Error",
15701570
"code": 7023
15711571
},
1572+
"Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.": {
1573+
"category": "Error",
1574+
"code": 7024
1575+
},
15721576
"You cannot rename this element.": {
15731577
"category": "Error",
15741578
"code": 8000

tests/baselines/reference/implicitAnyFromCircularInference.errors.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
// Error expected
44
var a: typeof a;
55
~
6-
!!! 'a' implicitly has type 'any' because type inference encountered a circularity.
6+
!!! 'a' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
77

88
// Error expected on b or c
99
var b: typeof c;
1010
var c: typeof b;
1111
~
12-
!!! 'c' implicitly has type 'any' because type inference encountered a circularity.
12+
!!! 'c' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
1313

1414
// Error expected
1515
var d: Array<typeof d>;
1616
~
17-
!!! 'd' implicitly has type 'any' because type inference encountered a circularity.
17+
!!! 'd' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation.
1818

1919
function f() { return f; }
2020

2121
// Error expected
2222
function g() { return g(); }
2323
~
24-
!!! 'g' implicitly has return type 'any' because type inference encountered a circularity.
24+
!!! 'g' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
2525

2626
// Error expected
2727
var f1 = function () {
@@ -30,17 +30,17 @@
3030
~~~~~~~~~~~~~~~~
3131
};
3232
~
33-
!!! Function implicitly has return type 'any' because type inference encountered a circularity.
33+
!!! Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
3434

3535
// Error expected
3636
var f2 = () => f2();
3737
~~~~~~~~~~
38-
!!! Function implicitly has return type 'any' because type inference encountered a circularity.
38+
!!! Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
3939

4040
// Error expected
4141
function h() {
4242
~
43-
!!! 'h' implicitly has return type 'any' because type inference encountered a circularity.
43+
!!! 'h' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
4444
return foo();
4545
function foo() {
4646
return h() || "hello";
@@ -57,7 +57,7 @@
5757
// Error expected
5858
s = foo(this);
5959
~~~~~~~~~~~~~~
60-
!!! 's' implicitly has type 'any' because type inference encountered a circularity.
60+
!!! 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.
6161
}
6262

6363
class D {
@@ -68,6 +68,6 @@
6868
~~~~~~~~~~~~~~~~~~~~~~
6969
}
7070
~~~~~
71-
!!! 'x' implicitly has type 'any' because type inference encountered a circularity.
71+
!!! 'x' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
7272
}
7373

0 commit comments

Comments
 (0)