mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Use packageId for suggestion to install @types/packageName (#21241)
This commit is contained in:
parent
b0d7d5a7ef
commit
ec37651308
@ -2063,9 +2063,9 @@ namespace ts {
|
||||
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
|
||||
}
|
||||
else if (noImplicitAny && moduleNotFoundError) {
|
||||
let errorInfo = !resolvedModule.isExternalLibraryImport ? undefined : chainDiagnosticMessages(/*details*/ undefined,
|
||||
let errorInfo = resolvedModule.packageId && 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);
|
||||
resolvedModule.packageId.name);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo,
|
||||
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
|
||||
moduleReference,
|
||||
|
||||
@ -8,8 +8,11 @@
|
||||
!!! 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) ====
|
||||
==== /node_modules/foo/package.json (0 errors) ====
|
||||
// This tests that `--noImplicitAny` disables untyped modules.
|
||||
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
==== /node_modules/foo/index.js (0 errors) ====
|
||||
This file is not processed.
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport_noImplicitAny.ts] ////
|
||||
|
||||
//// [index.js]
|
||||
//// [package.json]
|
||||
// This tests that `--noImplicitAny` disables untyped modules.
|
||||
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
//// [index.js]
|
||||
This file is not processed.
|
||||
|
||||
//// [a.ts]
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
/a.ts(1,22): error TS7016: Could not find a declaration file for module './node_modules/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 "./node_modules/foo";
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS7016: Could not find a declaration file for module './node_modules/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/package.json (0 errors) ====
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
==== /node_modules/foo/index.js (0 errors) ====
|
||||
This file is not processed.
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport_noImplicitAny_relativePath.ts] ////
|
||||
|
||||
//// [package.json]
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
//// [index.js]
|
||||
This file is not processed.
|
||||
|
||||
//// [a.ts]
|
||||
import * as foo from "./node_modules/foo";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import * as foo from "./node_modules/foo";
|
||||
>foo : Symbol(foo, Decl(a.ts, 0, 6))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import * as foo from "./node_modules/foo";
|
||||
>foo : any
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
// @noImplicitReferences: true
|
||||
// @currentDirectory: /
|
||||
// @noImplicitAny: true
|
||||
// This tests that `--noImplicitAny` disables untyped modules.
|
||||
|
||||
// @filename: /node_modules/foo/package.json
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
// @filename: /node_modules/foo/index.js
|
||||
This file is not processed.
|
||||
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
// @noImplicitReferences: true
|
||||
// @noImplicitAny: true
|
||||
|
||||
// @filename: /node_modules/foo/package.json
|
||||
{ "name": "foo", "version": "1.2.3" }
|
||||
|
||||
// @filename: /node_modules/foo/index.js
|
||||
This file is not processed.
|
||||
|
||||
// @filename: /a.ts
|
||||
import * as foo from "./node_modules/foo";
|
||||
Loading…
x
Reference in New Issue
Block a user