Skip to content

Commit 878f447

Browse files
Clarified file-not-found error for reference paths without extensions (#35956)
* Clarified file-not-found error for reference paths without extensions * Updated error message to include extensions * update baselines missed in merge Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent e60bbac commit 878f447

9 files changed

+48
-4
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,10 @@
43244324
"category": "Error",
43254325
"code": 6230
43264326
},
4327+
"Could not resolve the path '{0}' with the extensions: {1}.": {
4328+
"category": "Error",
4329+
"code": 6231
4330+
},
43274331

43284332
"Projects to reference": {
43294333
"category": "Message",

src/compiler/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ namespace ts {
19251925
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.Type_parameter_declarations_can_only_be_used_in_TypeScript_files));
19261926
return "skip";
19271927
}
1928-
// falls through
1928+
// falls through
19291929

19301930
case SyntaxKind.VariableStatement:
19311931
// Check modifiers
@@ -2270,7 +2270,7 @@ namespace ts {
22702270
}
22712271

22722272
const sourceFileWithAddedExtension = forEach(supportedExtensions, extension => getSourceFile(fileName + extension));
2273-
if (fail && !sourceFileWithAddedExtension) fail(Diagnostics.File_0_not_found, fileName + Extension.Ts);
2273+
if (fail && !sourceFileWithAddedExtension) fail(Diagnostics.Could_not_resolve_the_path_0_with_the_extensions_Colon_1, fileName, "'" + supportedExtensions.join("', '") + "'");
22742274
return sourceFileWithAddedExtension;
22752275
}
22762276
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/declarationEmitInvalidReferenceAllowJs.ts(1,22): error TS6231: Could not resolve the path 'tests/cases/compiler/invalid' with the extensions: '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
2+
3+
4+
==== tests/cases/compiler/declarationEmitInvalidReferenceAllowJs.ts (1 errors) ====
5+
/// <reference path="invalid" />
6+
~~~~~~~
7+
!!! error TS6231: Could not resolve the path 'tests/cases/compiler/invalid' with the extensions: '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
8+
var x = 0;
9+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [declarationEmitInvalidReferenceAllowJs.ts]
2+
/// <reference path="invalid" />
3+
var x = 0;
4+
5+
6+
//// [declarationEmitInvalidReferenceAllowJs.js]
7+
/// <reference path="invalid" />
8+
var x = 0;
9+
10+
11+
//// [declarationEmitInvalidReferenceAllowJs.d.ts]
12+
declare var x: number;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/declarationEmitInvalidReferenceAllowJs.ts ===
2+
/// <reference path="invalid" />
3+
var x = 0;
4+
>x : Symbol(x, Decl(declarationEmitInvalidReferenceAllowJs.ts, 1, 3))
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/declarationEmitInvalidReferenceAllowJs.ts ===
2+
/// <reference path="invalid" />
3+
var x = 0;
4+
>x : number
5+
>0 : 0
6+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error TS6053: File 'a.ts' not found.
22
error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
3+
error TS6231: Could not resolve the path 'a' with the extensions: '.ts', '.tsx', '.d.ts'.
34

45

56
!!! error TS6053: File 'a.ts' not found.
6-
!!! error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
7+
!!! error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
8+
!!! error TS6231: Could not resolve the path 'a' with the extensions: '.ts', '.tsx', '.d.ts'.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error TS6053: File 'a.ts' not found.
22
error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
3+
error TS6231: Could not resolve the path 'a' with the extensions: '.ts', '.tsx', '.d.ts'.
34

45

56
!!! error TS6053: File 'a.ts' not found.
6-
!!! error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
7+
!!! error TS6054: File 'a.t' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
8+
!!! error TS6231: Could not resolve the path 'a' with the extensions: '.ts', '.tsx', '.d.ts'.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @allowJs: true
2+
// @declaration: true
3+
/// <reference path="invalid" />
4+
var x = 0;

0 commit comments

Comments
 (0)