Skip to content

"Could not find a declaration file for module" error needs to use the unmangled package name where appropriate. #26121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2244,8 +2244,9 @@ namespace ts {
? chainDiagnosticMessages(
/*details*/ undefined,
typesPackageExists(packageId.name)
? 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
: Diagnostics.Try_npm_install_types_Slash_0_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
? 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_1
: Diagnostics.Try_npm_install_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
packageId.name,
getMangledNameForScopedPackage(packageId.name))
: undefined;
errorOrSuggestion(isError, errorNode, chainDiagnosticMessages(
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,7 @@
"category": "Error",
"code": 7034
},
"Try `npm install @types/{0}` if it exists or add a new declaration (.d.ts) file containing `declare module '{0}';`": {
"Try `npm install @types/{1}` if it exists or add a new declaration (.d.ts) file containing `declare module '{0}';`": {
"category": "Error",
"code": 7035
},
Expand All @@ -3921,7 +3921,7 @@
"category": "Error",
"code": 7039
},
"If the '{0}' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/{0}`": {
"If the '{0}' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/{1}`": {
"category": "Error",
"code": 7040
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/a.ts(1,22): error TS7016: Could not find a declaration file for module '@foo/bar'. '/node_modules/@foo/bar/index.js' implicitly has an 'any' type.
Try `npm install @types/foo__bar` if it exists or add a new declaration (.d.ts) file containing `declare module 'foo__bar';`
Try `npm install @types/foo__bar` if it exists or add a new declaration (.d.ts) file containing `declare module '@foo/bar';`


==== /a.ts (1 errors) ====
import * as foo from "@foo/bar";
~~~~~~~~~~
!!! error TS7016: Could not find a declaration file for module '@foo/bar'. '/node_modules/@foo/bar/index.js' implicitly has an 'any' type.
!!! error TS7016: Try `npm install @types/foo__bar` if it exists or add a new declaration (.d.ts) file containing `declare module 'foo__bar';`
!!! error TS7016: Try `npm install @types/foo__bar` if it exists or add a new declaration (.d.ts) file containing `declare module '@foo/bar';`

==== /node_modules/@foo/bar/package.json (0 errors) ====
{ "name": "@foo/bar", "version": "1.2.3" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
If the 'foo' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/foo`
/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.
Try `npm install @types/bar` if it exists or add a new declaration (.d.ts) file containing `declare module 'bar';`
/a.ts(5,30): error TS7016: Could not find a declaration file for module '@scope/foo/sub'. '/node_modules/@scope/foo/sub.js' implicitly has an 'any' type.
If the '@scope/foo' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/scope__foo`
/a.ts(6,30): error TS7016: Could not find a declaration file for module '@scope/bar/sub'. '/node_modules/@scope/bar/sub.js' implicitly has an 'any' type.
Try `npm install @types/scope__bar` if it exists or add a new declaration (.d.ts) file containing `declare module '@scope/bar';`


==== /a.ts (2 errors) ====
==== /a.ts (4 errors) ====
import * as foo from "foo";
import * as fooSub from "foo/sub";
~~~~~~~~~
Expand All @@ -14,6 +18,15 @@
~~~~~~~~~
!!! error TS7016: Could not find a declaration file for module 'bar/sub'. '/node_modules/bar/sub.js' implicitly has an 'any' type.
!!! error TS7016: Try `npm install @types/bar` if it exists or add a new declaration (.d.ts) file containing `declare module 'bar';`
import * as scopeFoo from "@scope/foo";
import * as scopeFooSub from "@scope/foo/sub";
~~~~~~~~~~~~~~~~
!!! error TS7016: Could not find a declaration file for module '@scope/foo/sub'. '/node_modules/@scope/foo/sub.js' implicitly has an 'any' type.
!!! error TS7016: If the '@scope/foo' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/scope__foo`
import * as scopeBarSub from "@scope/bar/sub";
~~~~~~~~~~~~~~~~
!!! error TS7016: Could not find a declaration file for module '@scope/bar/sub'. '/node_modules/@scope/bar/sub.js' implicitly has an 'any' type.
!!! error TS7016: Try `npm install @types/scope__bar` if it exists or add a new declaration (.d.ts) file containing `declare module '@scope/bar';`

==== /node_modules/@types/foo/index.d.ts (0 errors) ====
export const foo: number;
Expand All @@ -32,4 +45,22 @@

==== /node_modules/bar/package.json (0 errors) ====
{ "name": "bar", "version": "1.2.3" }

==== /node_modules/@types/scope__foo/index.d.ts (0 errors) ====
export const foo: number;

==== /node_modules/@types/scope__foo/package.json (0 errors) ====
{ "name": "@types/scope__foo", "version": "1.2.3" }

==== /node_modules/@scope/foo/sub.js (0 errors) ====
const x = 0;

==== /node_modules/@scope/foo/package.json (0 errors) ====
{ "name": "@scope/foo", "version": "1.2.3" }

==== /node_modules/@scope/bar/sub.js (0 errors) ====
const x = 0;

==== /node_modules/@scope/bar/package.json (0 errors) ====
{ "name": "@scope/bar", "version": "1.2.3" }

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,31 @@ const x = 0;
//// [package.json]
{ "name": "bar", "version": "1.2.3" }

//// [index.d.ts]
export const foo: number;

//// [package.json]
{ "name": "@types/scope__foo", "version": "1.2.3" }

//// [sub.js]
const x = 0;

//// [package.json]
{ "name": "@scope/foo", "version": "1.2.3" }

//// [sub.js]
const x = 0;

//// [package.json]
{ "name": "@scope/bar", "version": "1.2.3" }

//// [a.ts]
import * as foo from "foo";
import * as fooSub from "foo/sub";
import * as barSub from "bar/sub";
import * as scopeFoo from "@scope/foo";
import * as scopeFooSub from "@scope/foo/sub";
import * as scopeBarSub from "@scope/bar/sub";


//// [a.js]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ import * as fooSub from "foo/sub";
import * as barSub from "bar/sub";
>barSub : Symbol(barSub, Decl(a.ts, 2, 6))

import * as scopeFoo from "@scope/foo";
>scopeFoo : Symbol(scopeFoo, Decl(a.ts, 3, 6))

import * as scopeFooSub from "@scope/foo/sub";
>scopeFooSub : Symbol(scopeFooSub, Decl(a.ts, 4, 6))

import * as scopeBarSub from "@scope/bar/sub";
>scopeBarSub : Symbol(scopeBarSub, Decl(a.ts, 5, 6))

=== /node_modules/@types/foo/index.d.ts ===
export const foo: number;
>foo : Symbol(foo, Decl(index.d.ts, 0, 12))

=== /node_modules/@types/scope__foo/index.d.ts ===
export const foo: number;
>foo : Symbol(foo, Decl(index.d.ts, 0, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ import * as fooSub from "foo/sub";
import * as barSub from "bar/sub";
>barSub : any

import * as scopeFoo from "@scope/foo";
>scopeFoo : typeof scopeFoo

import * as scopeFooSub from "@scope/foo/sub";
>scopeFooSub : any

import * as scopeBarSub from "@scope/bar/sub";
>scopeBarSub : any

=== /node_modules/@types/foo/index.d.ts ===
export const foo: number;
>foo : number

=== /node_modules/@types/scope__foo/index.d.ts ===
export const foo: number;
>foo : number

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,28 @@ const x = 0;
// @Filename: /node_modules/bar/package.json
{ "name": "bar", "version": "1.2.3" }

// @Filename: /node_modules/@types/scope__foo/index.d.ts
export const foo: number;

// @Filename: /node_modules/@types/scope__foo/package.json
{ "name": "@types/scope__foo", "version": "1.2.3" }

// @Filename: /node_modules/@scope/foo/sub.js
const x = 0;

// @Filename: /node_modules/@scope/foo/package.json
{ "name": "@scope/foo", "version": "1.2.3" }

// @Filename: /node_modules/@scope/bar/sub.js
const x = 0;

// @Filename: /node_modules/@scope/bar/package.json
{ "name": "@scope/bar", "version": "1.2.3" }

// @Filename: /a.ts
import * as foo from "foo";
import * as fooSub from "foo/sub";
import * as barSub from "bar/sub";
import * as scopeFoo from "@scope/foo";
import * as scopeFooSub from "@scope/foo/sub";
import * as scopeBarSub from "@scope/bar/sub";