Skip to content

Commit d1d3f73

Browse files
improve error message TS2307
1 parent eadf44d commit d1d3f73

File tree

116 files changed

+996
-996
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+996
-996
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ namespace ts {
22242224
}
22252225

22262226
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol | undefined {
2227-
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0);
2227+
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module);
22282228
}
22292229

22302230
function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation = false): Symbol | undefined {

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@
10361036
"category": "Error",
10371037
"code": 2306
10381038
},
1039-
"Cannot find module '{0}'.": {
1039+
"Cannot find module '{0}' or cannot find corresponding type declarations for this module.": {
10401040
"category": "Error",
10411041
"code": 2307
10421042
},

src/services/codefixes/fixCannotFindModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ts.codefix {
44
const fixIdInstallTypesPackage = "installTypesPackage";
55
const fixIdGenerateTypes = "generateTypes";
66

7-
const errorCodeCannotFindModule = Diagnostics.Cannot_find_module_0.code;
7+
const errorCodeCannotFindModule = Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module.code;
88
const errorCodes = [
99
errorCodeCannotFindModule,
1010
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type.code,

src/testRunner/unittests/tscWatchMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace ts.tscWatch {
230230

231231
function getDiagnosticModuleNotFoundOfFile(program: Program, file: File, moduleName: string) {
232232
const quotedModuleName = `"${moduleName}"`;
233-
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0, moduleName);
233+
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, moduleName);
234234
}
235235

236236
describe("tsc-watch program updates", () => {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,7 +4721,7 @@ namespace ts.projectSystem {
47214721
host.runQueuedTimeoutCallbacks();
47224722
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
47234723
verifyDiagnostics(diags, [
4724-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4724+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, errorTextArguments: ["./moduleFile"] }
47254725
]);
47264726
assert.equal(diags.length, 1);
47274727

@@ -4772,7 +4772,7 @@ namespace ts.projectSystem {
47724772
host.runQueuedTimeoutCallbacks();
47734773
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
47744774
verifyDiagnostics(diags, [
4775-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4775+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, errorTextArguments: ["./moduleFile"] }
47764776
]);
47774777

47784778
moduleFile.path = moduleFileOldPath;
@@ -4847,7 +4847,7 @@ namespace ts.projectSystem {
48474847
);
48484848
let diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
48494849
verifyDiagnostics(diags, [
4850-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4850+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, errorTextArguments: ["./moduleFile"] }
48514851
]);
48524852

48534853
host.reloadFS([file1, moduleFile]);
@@ -4904,7 +4904,7 @@ namespace ts.projectSystem {
49044904
checkErrorMessage(session, "semanticDiag", {
49054905
file: file1.path,
49064906
diagnostics: [
4907-
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0, ["pad"])
4907+
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, ["pad"])
49084908
],
49094909
});
49104910
session.clearMessages();
@@ -7081,8 +7081,8 @@ namespace ts.projectSystem {
70817081
let diags = project.getLanguageService().getSemanticDiagnostics(root.path);
70827082
assert.equal(diags.length, 1);
70837083
const diag = diags[0];
7084-
assert.equal(diag.code, Diagnostics.Cannot_find_module_0.code);
7085-
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar'.");
7084+
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module.code);
7085+
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar' or cannot find corresponding type declarations for this module.");
70867086
callsTrackingHost.verifyCalledOn(CalledMapsWithSingleArg.fileExists, imported.path);
70877087

70887088

@@ -7315,8 +7315,8 @@ namespace ts.projectSystem {
73157315

73167316
const project = service.configuredProjects.get(tsconfig.path)!;
73177317
checkProjectActualFiles(project, files.map(f => f.path));
7318-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7319-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7318+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug' or cannot find corresponding type declarations for this module."]);
7319+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug' or cannot find corresponding type declarations for this module."]);
73207320

73217321
const debugTypesFile: File = {
73227322
path: `${projectLocation}/node_modules/debug/index.d.ts`,
@@ -7523,7 +7523,7 @@ namespace ts.projectSystem {
75237523

75247524
const project = service.configuredProjects.get(tsconfig.path)!;
75257525
checkProjectActualFiles(project, files.map(f => f.path));
7526-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7526+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug' or cannot find corresponding type declarations for this module."]);
75277527

75287528
const debugTypesFile: File = {
75297529
path: `${projectLocation}/node_modules/@types/debug/index.d.ts`,
@@ -8498,7 +8498,7 @@ new C();`
84988498
verifyWatchedFilesAndDirectories(session.host, filesInProjectWithUnresolvedModule, watchedDirectoriesWithUnresolvedModule, nonRecursiveWatchedDirectories);
84998499
const startOffset = recognizersDateTimeSrcFile.content.indexOf('"') + 1;
85008500
verifyErrors(session, [
8501-
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0, [moduleName])
8501+
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0_or_cannot_find_corresponding_type_declarations_for_this_module, [moduleName])
85028502
]);
85038503
}
85048504

tests/baselines/reference/aliasesInSystemModule1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/aliasesInSystemModule1.ts(1,24): error TS2307: Cannot find module 'foo'.
1+
tests/cases/compiler/aliasesInSystemModule1.ts(1,24): error TS2307: Cannot find module 'foo' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/aliasesInSystemModule1.ts (1 errors) ====
55
import alias = require('foo');
66
~~~~~
7-
!!! error TS2307: Cannot find module 'foo'.
7+
!!! error TS2307: Cannot find module 'foo' or cannot find corresponding type declarations for this module.
88
import cls = alias.Class;
99
export import cls2 = alias.Class;
1010

tests/baselines/reference/aliasesInSystemModule2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/aliasesInSystemModule2.ts(1,21): error TS2307: Cannot find module 'foo'.
1+
tests/cases/compiler/aliasesInSystemModule2.ts(1,21): error TS2307: Cannot find module 'foo' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/aliasesInSystemModule2.ts (1 errors) ====
55
import {alias} from "foo";
66
~~~~~
7-
!!! error TS2307: Cannot find module 'foo'.
7+
!!! error TS2307: Cannot find module 'foo' or cannot find corresponding type declarations for this module.
88
import cls = alias.Class;
99
export import cls2 = alias.Class;
1010

tests/baselines/reference/ambientExternalModuleInAnotherExternalModule.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(4,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.
2-
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): error TS2307: Cannot find module 'ext'.
2+
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): error TS2307: Cannot find module 'ext' or cannot find corresponding type declarations for this module.
33

44

55
==== tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts (2 errors) ====
@@ -15,5 +15,5 @@ tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): erro
1515
// Cannot resolve this ext module reference
1616
import ext = require("ext");
1717
~~~~~
18-
!!! error TS2307: Cannot find module 'ext'.
18+
!!! error TS2307: Cannot find module 'ext' or cannot find corresponding type declarations for this module.
1919
var x = ext;

tests/baselines/reference/ambientExternalModuleWithRelativeExternalImportDeclaration.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
2-
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,25): error TS2307: Cannot find module './SubModule'.
2+
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,25): error TS2307: Cannot find module './SubModule' or cannot find corresponding type declarations for this module.
33

44

55
==== tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts (2 errors) ====
@@ -8,7 +8,7 @@ tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.
88
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
!!! error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
1010
~~~~~~~~~~~~~
11-
!!! error TS2307: Cannot find module './SubModule'.
11+
!!! error TS2307: Cannot find module './SubModule' or cannot find corresponding type declarations for this module.
1212
class SubModule {
1313
public static StaticVar: number;
1414
public InstanceVar: number;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/amdDependencyComment1.ts(3,21): error TS2307: Cannot find module 'm2'.
1+
tests/cases/compiler/amdDependencyComment1.ts(3,21): error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/amdDependencyComment1.ts (1 errors) ====
55
///<amd-dependency path='bar'/>
66

77
import m1 = require("m2")
88
~~~~
9-
!!! error TS2307: Cannot find module 'm2'.
9+
!!! error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
1010
m1.f();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/amdDependencyComment2.ts(3,21): error TS2307: Cannot find module 'm2'.
1+
tests/cases/compiler/amdDependencyComment2.ts(3,21): error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/amdDependencyComment2.ts (1 errors) ====
55
///<amd-dependency path='bar'/>
66

77
import m1 = require("m2")
88
~~~~
9-
!!! error TS2307: Cannot find module 'm2'.
9+
!!! error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
1010
m1.f();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find module 'm2'.
1+
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/amdDependencyCommentName1.ts (1 errors) ====
55
///<amd-dependency path='bar' name='b'/>
66

77
import m1 = require("m2")
88
~~~~
9-
!!! error TS2307: Cannot find module 'm2'.
9+
!!! error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
1010
m1.f();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find module 'm2'.
1+
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/amdDependencyCommentName2.ts (1 errors) ====
55
///<amd-dependency path='bar' name='b'/>
66

77
import m1 = require("m2")
88
~~~~
9-
!!! error TS2307: Cannot find module 'm2'.
9+
!!! error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
1010
m1.f();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find module 'm2'.
1+
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/compiler/amdDependencyCommentName3.ts (1 errors) ====
@@ -8,5 +8,5 @@ tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot fi
88

99
import m1 = require("m2")
1010
~~~~
11-
!!! error TS2307: Cannot find module 'm2'.
11+
!!! error TS2307: Cannot find module 'm2' or cannot find corresponding type declarations for this module.
1212
m1.f();
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/amdDependencyCommentName4.ts(8,21): error TS2307: Cannot find module 'aliasedModule1'.
2-
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2'.
3-
tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3'.
4-
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4'.
1+
tests/cases/compiler/amdDependencyCommentName4.ts(8,21): error TS2307: Cannot find module 'aliasedModule1' or cannot find corresponding type declarations for this module.
2+
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2' or cannot find corresponding type declarations for this module.
3+
tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3' or cannot find corresponding type declarations for this module.
4+
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4' or cannot find corresponding type declarations for this module.
55

66

77
==== tests/cases/compiler/amdDependencyCommentName4.ts (4 errors) ====
@@ -14,22 +14,22 @@ tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot f
1414

1515
import r1 = require("aliasedModule1");
1616
~~~~~~~~~~~~~~~~
17-
!!! error TS2307: Cannot find module 'aliasedModule1'.
17+
!!! error TS2307: Cannot find module 'aliasedModule1' or cannot find corresponding type declarations for this module.
1818
r1;
1919

2020
import {p1, p2, p3} from "aliasedModule2";
2121
~~~~~~~~~~~~~~~~
22-
!!! error TS2307: Cannot find module 'aliasedModule2'.
22+
!!! error TS2307: Cannot find module 'aliasedModule2' or cannot find corresponding type declarations for this module.
2323
p1;
2424

2525
import d from "aliasedModule3";
2626
~~~~~~~~~~~~~~~~
27-
!!! error TS2307: Cannot find module 'aliasedModule3'.
27+
!!! error TS2307: Cannot find module 'aliasedModule3' or cannot find corresponding type declarations for this module.
2828
d;
2929

3030
import * as ns from "aliasedModule4";
3131
~~~~~~~~~~~~~~~~
32-
!!! error TS2307: Cannot find module 'aliasedModule4'.
32+
!!! error TS2307: Cannot find module 'aliasedModule4' or cannot find corresponding type declarations for this module.
3333
ns;
3434

3535
import "unaliasedModule2";

tests/baselines/reference/asyncAwaitIsolatedModules_es2017.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts(1,27): error TS2307: Cannot find module 'missing'.
1+
tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts(1,27): error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts (1 errors) ====
55
import { MyPromise } from "missing";
66
~~~~~~~~~
7-
!!! error TS2307: Cannot find module 'missing'.
7+
!!! error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
88

99
declare var p: Promise<number>;
1010
declare var mp: MyPromise<number>;

tests/baselines/reference/asyncAwaitIsolatedModules_es5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts(1,27): error TS2307: Cannot find module 'missing'.
1+
tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts(1,27): error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts (1 errors) ====
55
import { MyPromise } from "missing";
66
~~~~~~~~~
7-
!!! error TS2307: Cannot find module 'missing'.
7+
!!! error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
88

99
declare var p: Promise<number>;
1010
declare var mp: MyPromise<number>;

tests/baselines/reference/asyncAwaitIsolatedModules_es6.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2307: Cannot find module 'missing'.
1+
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
22

33

44
==== tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts (1 errors) ====
55
import { MyPromise } from "missing";
66
~~~~~~~~~
7-
!!! error TS2307: Cannot find module 'missing'.
7+
!!! error TS2307: Cannot find module 'missing' or cannot find corresponding type declarations for this module.
88

99
declare var p: Promise<number>;
1010
declare var mp: MyPromise<number>;

0 commit comments

Comments
 (0)