Improve message for untyped module w/noImplicitAny

Now there is an elaboration that suggests npm install @types/foo or
adding `declare module 'foo'` in a separate file.
This commit is contained in:
Nathan Shively-Sanders
2017-04-24 10:43:58 -07:00
parent 5783435edc
commit d863aef57e
2 changed files with 9 additions and 1 deletions

View File

@@ -1641,10 +1641,14 @@ namespace ts {
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
}
else if (noImplicitAny && moduleNotFoundError) {
error(errorNode,
let errorInfo = chainDiagnosticMessages(undefined,
Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_adding_declare_module_0_in_a_separate_file,
moduleReference);
errorInfo = chainDiagnosticMessages(errorInfo,
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
moduleReference,
resolvedModule.resolvedFileName);
diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
}
// Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
return undefined;

View File

@@ -3310,6 +3310,10 @@
"category": "Error",
"code": 7034
},
"Try `npm install @types/{0}` if it exists or adding `declare module '{0}'` in a separate file.": {
"category": "Error",
"code": 7035
},
"You cannot rename this element.": {
"category": "Error",
"code": 8000