Skip to content

Commit d863aef

Browse files
committed
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.
1 parent 5783435 commit d863aef

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,10 +1641,14 @@ namespace ts {
16411641
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
16421642
}
16431643
else if (noImplicitAny && moduleNotFoundError) {
1644-
error(errorNode,
1644+
let errorInfo = chainDiagnosticMessages(undefined,
1645+
Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_adding_declare_module_0_in_a_separate_file,
1646+
moduleReference);
1647+
errorInfo = chainDiagnosticMessages(errorInfo,
16451648
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
16461649
moduleReference,
16471650
resolvedModule.resolvedFileName);
1651+
diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
16481652
}
16491653
// Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
16501654
return undefined;

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,6 +3310,10 @@
33103310
"category": "Error",
33113311
"code": 7034
33123312
},
3313+
"Try `npm install @types/{0}` if it exists or adding `declare module '{0}'` in a separate file.": {
3314+
"category": "Error",
3315+
"code": 7035
3316+
},
33133317
"You cannot rename this element.": {
33143318
"category": "Error",
33153319
"code": 8000

0 commit comments

Comments
 (0)