You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: debug and implement correct diagnostic logic for unsafe import rewrites
The diagnostic for error TS2876 was not being triggered because the rewrite check logic was placed outside the `errorNode != nil` block. Moving it inside the error handling block and fixing the conditional logic now correctly detects when a module specifier looks like a file name but resolves to a different location, triggering the appropriate "unsafe to rewrite" error.
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
2
+
3
+
4
+
==== index.ts (1 errors) ====
5
+
import foo = require("./foo.ts"); // Error
6
+
~~~~~~~~~~
7
+
!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
Copy file name to clipboardExpand all lines: testdata/baselines/reference/submodule/conformance/cjsErrors(module=node18).errors.txt.diff
+10-11Lines changed: 10 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,14 @@
2
2
+++ new.cjsErrors(module=node18).errors.txt
3
3
@@= skipped -0, +0 lines =@@
4
4
-index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts".
5
-
-
6
-
-
7
-
-==== index.ts (1 errors) ====
8
-
- import foo = require("./foo.ts"); // Error
9
-
- ~~~~~~~~~~
5
+
+index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
6
+
7
+
8
+
==== index.ts (1 errors) ====
9
+
import foo = require("./foo.ts"); // Error
10
+
~~~~~~~~~~
10
11
-!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts".
11
-
- import type _foo = require("./foo.ts"); // Ok
12
-
-
13
-
-==== foo.ts/index.ts (0 errors) ====
14
-
- export = {};
15
-
-
16
-
+<no content>
12
+
+!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
2
+
3
+
4
+
==== index.ts (1 errors) ====
5
+
import foo = require("./foo.ts"); // Error
6
+
~~~~~~~~~~
7
+
!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
Copy file name to clipboardExpand all lines: testdata/baselines/reference/submodule/conformance/cjsErrors(module=nodenext).errors.txt.diff
+10-11Lines changed: 10 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,14 @@
2
2
+++ new.cjsErrors(module=nodenext).errors.txt
3
3
@@= skipped -0, +0 lines =@@
4
4
-index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts".
5
-
-
6
-
-
7
-
-==== index.ts (1 errors) ====
8
-
- import foo = require("./foo.ts"); // Error
9
-
- ~~~~~~~~~~
5
+
+index.ts(1,22): error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
6
+
7
+
8
+
==== index.ts (1 errors) ====
9
+
import foo = require("./foo.ts"); // Error
10
+
~~~~~~~~~~
10
11
-!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./foo.ts/index.ts".
11
-
- import type _foo = require("./foo.ts"); // Ok
12
-
-
13
-
-==== foo.ts/index.ts (0 errors) ====
14
-
- export = {};
15
-
-
16
-
+<no content>
12
+
+!!! error TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "foo.ts/index.ts".
0 commit comments