Skip to content

Commit a933da9

Browse files
improve error message TS2307
1 parent a2205ad commit a933da9

File tree

117 files changed

+997
-997
lines changed

Some content is hidden

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

117 files changed

+997
-997
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ namespace ts {
22472247
}
22482248

22492249
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol | undefined {
2250-
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0);
2250+
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations);
22512251
}
22522252

22532253
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
@@ -1044,7 +1044,7 @@
10441044
"category": "Error",
10451045
"code": 2306
10461046
},
1047-
"Cannot find module '{0}'.": {
1047+
"Cannot find module '{0}' or its corresponding type declarations.": {
10481048
"category": "Error",
10491049
"code": 2307
10501050
},

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_its_corresponding_type_declarations.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/tsbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export const b = new A();`);
451451
];
452452
verifyBuild(fs => modifyFsBTsToNonRelativeImport(fs, "node"),
453453
allExpectedOutputs,
454-
[Diagnostics.Cannot_find_module_0],
454+
[Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations],
455455
expectedFileTraces);
456456
});
457457
});

src/testRunner/unittests/tscWatchMode.ts

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

233233
function getDiagnosticModuleNotFoundOfFile(program: Program, file: File, moduleName: string) {
234234
const quotedModuleName = `"${moduleName}"`;
235-
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0, moduleName);
235+
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, moduleName);
236236
}
237237

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

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,7 +4792,7 @@ var x = 10;`
47924792
host.runQueuedTimeoutCallbacks();
47934793
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
47944794
verifyDiagnostics(diags, [
4795-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4795+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
47964796
]);
47974797
assert.equal(diags.length, 1);
47984798

@@ -4843,7 +4843,7 @@ var x = 10;`
48434843
host.runQueuedTimeoutCallbacks();
48444844
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
48454845
verifyDiagnostics(diags, [
4846-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4846+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
48474847
]);
48484848

48494849
moduleFile.path = moduleFileOldPath;
@@ -4918,7 +4918,7 @@ var x = 10;`
49184918
);
49194919
let diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
49204920
verifyDiagnostics(diags, [
4921-
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
4921+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
49224922
]);
49234923

49244924
host.reloadFS([file1, moduleFile]);
@@ -4975,7 +4975,7 @@ var x = 10;`
49754975
checkErrorMessage(session, "semanticDiag", {
49764976
file: file1.path,
49774977
diagnostics: [
4978-
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0, ["pad"])
4978+
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, ["pad"])
49794979
],
49804980
});
49814981
session.clearMessages();
@@ -7152,8 +7152,8 @@ var x = 10;`
71527152
let diags = project.getLanguageService().getSemanticDiagnostics(root.path);
71537153
assert.equal(diags.length, 1);
71547154
const diag = diags[0];
7155-
assert.equal(diag.code, Diagnostics.Cannot_find_module_0.code);
7156-
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar'.");
7155+
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations.code);
7156+
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar' or its corresponding type declarations.");
71577157
callsTrackingHost.verifyCalledOn(CalledMapsWithSingleArg.fileExists, imported.path);
71587158

71597159

@@ -7386,8 +7386,8 @@ var x = 10;`
73867386

73877387
const project = service.configuredProjects.get(tsconfig.path)!;
73887388
checkProjectActualFiles(project, files.map(f => f.path));
7389-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7390-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7389+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);
7390+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);
73917391

73927392
const debugTypesFile: File = {
73937393
path: `${projectLocation}/node_modules/debug/index.d.ts`,
@@ -7594,7 +7594,7 @@ var x = 10;`
75947594

75957595
const project = service.configuredProjects.get(tsconfig.path)!;
75967596
checkProjectActualFiles(project, files.map(f => f.path));
7597-
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
7597+
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);
75987598

75997599
const debugTypesFile: File = {
76007600
path: `${projectLocation}/node_modules/@types/debug/index.d.ts`,
@@ -8552,7 +8552,7 @@ new C();`
85528552
verifyWatchedFilesAndDirectories(session.host, filesInProjectWithUnresolvedModule, watchedDirectoriesWithUnresolvedModule, nonRecursiveWatchedDirectories);
85538553
const startOffset = recognizersDateTimeSrcFile.content.indexOf('"') + 1;
85548554
verifyErrors(session, [
8555-
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0, [moduleName])
8555+
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, [moduleName])
85568556
]);
85578557
}
85588558

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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
2+
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2' or its corresponding type declarations.
3+
tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3' or its corresponding type declarations.
4+
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4' or its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
2323
p1;
2424

2525
import d from "aliasedModule3";
2626
~~~~~~~~~~~~~~~~
27-
!!! error TS2307: Cannot find module 'aliasedModule3'.
27+
!!! error TS2307: Cannot find module 'aliasedModule3' or its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
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 its corresponding type declarations.
88

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

tests/baselines/reference/badExternalModuleReference.errors.txt

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

33

44
==== tests/cases/compiler/badExternalModuleReference.ts (1 errors) ====
55
import a1 = require("garbage");
66
~~~~~~~~~
7-
!!! error TS2307: Cannot find module 'garbage'.
7+
!!! error TS2307: Cannot find module 'garbage' or its corresponding type declarations.
88
export declare var a: {
99
test1: a1.connectModule;
1010
(): a1.connectExport;

0 commit comments

Comments
 (0)