Skip to content

Commit f406e1f

Browse files
author
Andy Hanson
committed
Add different extra diagnostic text if the @types package exists
1 parent 19090aa commit f406e1f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,12 @@ namespace ts {
22832283
}
22842284

22852285
function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void {
2286-
const errorInfo = packageId && !typesPackageExists(packageId.name)
2286+
const errorInfo = packageId
22872287
? chainDiagnosticMessages(
22882288
/*details*/ undefined,
2289-
Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
2289+
typesPackageExists(packageId.name)
2290+
? Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_0
2291+
: Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
22902292
getMangledNameForScopedPackage(packageId.name))
22912293
: undefined;
22922294
errorOrSuggestion(isError, errorNode, chainDiagnosticMessages(

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,7 @@
36363636
"category": "Message",
36373637
"code": 6353
36383638
},
3639-
3639+
36403640
"Project '{0}' is up to date with .d.ts files from its dependencies": {
36413641
"category": "Message",
36423642
"code": 6354
@@ -3836,6 +3836,10 @@
38363836
"category": "Error",
38373837
"code": 7039
38383838
},
3839+
"If the '{0}' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/{0}`": {
3840+
"category": "Error",
3841+
"code": 7040
3842+
},
38393843
"You cannot rename this element.": {
38403844
"category": "Error",
38413845
"code": 8000

tests/baselines/reference/untypedModuleImport_noImplicitAny_typesForPackageExist.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/a.ts(2,25): error TS7016: Could not find a declaration file for module 'foo/sub'. '/node_modules/foo/sub.js' implicitly has an 'any' type.
2+
If the 'foo' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/foo`
23
/a.ts(3,25): error TS7016: Could not find a declaration file for module 'bar/sub'. '/node_modules/bar/sub.js' implicitly has an 'any' type.
34
Try `npm install @types/bar` if it exists or add a new declaration (.d.ts) file containing `declare module 'bar';`
45

@@ -8,6 +9,7 @@
89
import * as fooSub from "foo/sub";
910
~~~~~~~~~
1011
!!! error TS7016: Could not find a declaration file for module 'foo/sub'. '/node_modules/foo/sub.js' implicitly has an 'any' type.
12+
!!! error TS7016: If the 'foo' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/foo`
1113
import * as barSub from "bar/sub";
1214
~~~~~~~~~
1315
!!! error TS7016: Could not find a declaration file for module 'bar/sub'. '/node_modules/bar/sub.js' implicitly has an 'any' type.

0 commit comments

Comments
 (0)