Skip to content

Commit 78748c0

Browse files
More actionable "must have annotation" message (microsoft#35839)
* Give an actionable elaboration. * Accepted baselines. * Less words. * Accepted baselines.
1 parent f84b2d2 commit 78748c0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19045,7 +19045,7 @@ namespace ts {
1904519045
return getTypeOfSymbol(symbol);
1904619046
}
1904719047
if (diagnostic && symbol.valueDeclaration) {
19048-
addRelatedInfo(diagnostic, createDiagnosticForNode(symbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(symbol)));
19048+
addRelatedInfo(diagnostic, createDiagnosticForNode(symbol.valueDeclaration, Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol)));
1904919049
}
1905019050
}
1905119051
}

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,10 @@
28512851
"category": "Error",
28522852
"code": 2781
28532853
},
2854+
"'{0}' needs an explicit type annotation.": {
2855+
"category": "Message",
2856+
"code": 2782
2857+
},
28542858

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

tests/baselines/reference/assertionTypePredicates1.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(149,5): error TS
184184
assert(typeof x === "string"); // Error
185185
~~~~~~
186186
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
187-
!!! related TS2728 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' is declared here.
187+
!!! related TS2782 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' needs an explicit type annotation.
188188
const a = [assert];
189189
a[0](typeof x === "string"); // Error
190190
~~~~
@@ -193,7 +193,7 @@ tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(149,5): error TS
193193
t1.assert(typeof x === "string"); // Error
194194
~~~~~~~~~
195195
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
196-
!!! related TS2728 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:148:11: 't1' is declared here.
196+
!!! related TS2782 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:148:11: 't1' needs an explicit type annotation.
197197
const t2: Test = new Test();
198198
t2.assert(typeof x === "string");
199199
}

0 commit comments

Comments
 (0)