Merge pull request #15350 from Microsoft/improve-message-for-untyped-module

Improve message for untyped module with noImplicitAny
This commit is contained in:
Nathan Shively-Sanders 2017-04-24 16:13:27 -07:00 committed by GitHub
commit da5fd936e6
3 changed files with 11 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(/*details*/ undefined,
Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
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 add a new declaration (.d.ts) file containing `declare module '{0}';`": {
"category": "Error",
"code": 7035
},
"You cannot rename this element.": {
"category": "Error",
"code": 8000

View File

@ -1,10 +1,12 @@
/a.ts(1,22): error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.js' implicitly has an 'any' type.
Try `npm install @types/foo` if it exists or add a new declaration (.d.ts) file containing `declare module 'foo';`
==== /a.ts (1 errors) ====
import * as foo from "foo";
~~~~~
!!! error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.js' implicitly has an 'any' type.
!!! error TS7016: Try `npm install @types/foo` if it exists or add a new declaration (.d.ts) file containing `declare module 'foo';`
==== /node_modules/foo/index.js (0 errors) ====
// This tests that `--noImplicitAny` disables untyped modules.