More actionable "must have annotation" message (#35839)

* Give an actionable elaboration.

* Accepted baselines.

* Less words.

* Accepted baselines.
This commit is contained in:
Daniel Rosenwasser
2020-01-07 16:46:14 -08:00
committed by GitHub
parent f84b2d20a9
commit 78748c0a35
3 changed files with 7 additions and 3 deletions

View File

@@ -19045,7 +19045,7 @@ namespace ts {
return getTypeOfSymbol(symbol);
}
if (diagnostic && symbol.valueDeclaration) {
addRelatedInfo(diagnostic, createDiagnosticForNode(symbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(symbol)));
addRelatedInfo(diagnostic, createDiagnosticForNode(symbol.valueDeclaration, Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol)));
}
}
}

View File

@@ -2851,6 +2851,10 @@
"category": "Error",
"code": 2781
},
"'{0}' needs an explicit type annotation.": {
"category": "Message",
"code": 2782
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View File

@@ -184,7 +184,7 @@ tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(149,5): error TS
assert(typeof x === "string"); // Error
~~~~~~
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
!!! related TS2728 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' is declared here.
!!! related TS2782 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' needs an explicit type annotation.
const a = [assert];
a[0](typeof x === "string"); // Error
~~~~
@@ -193,7 +193,7 @@ tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(149,5): error TS
t1.assert(typeof x === "string"); // Error
~~~~~~~~~
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
!!! related TS2728 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:148:11: 't1' is declared here.
!!! related TS2782 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:148:11: 't1' needs an explicit type annotation.
const t2: Test = new Test();
t2.assert(typeof x === "string");
}