-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbolFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
move to new file extension nodenext
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about extensions
β― Playground Link
N/A Only applies to multi-file refactoring
π» Code
// Refactor this function to a new file
function someLibFn(): string {
return someOtherFn();
}
function someOtherFn(): string {
return "hello world!";
}
console.log(someLibFn());
π Actual behavior
The import generated is missing the .js
extension.
i.e. This is generated:
import { someLibFn } from "./someLibFn";
Similarly in the other file the reverse import is also missing it's extension:
import { someOtherFn } from "./example";
This broken refactor produces a predictable TS error:
Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './someLibFn.js'?ts(2835)
See also as video:
Screencast.from.11-09-22.00.10.49.webm
π Expected behavior
It should generate with the .js
extension as (and ditto for the other file):
import { someLibFn } from "./someLibFn.js";
Notes
This is almost certainly related to #46290 . However this doesn't really have anything to do with the vscode specific option importModuleSpecifierEnding
, so I made a separate issue.
tsconfig.json
In case this issue is caused by a combination of settings here is the full tsconfig.json
:
chen-ye
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbolFix AvailableA PR has been opened for this issueA PR has been opened for this issue