microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.22k stars 12.39k forks source link

"typescript.preferences.importModuleSpecifierEnding": "js" causes duplicate extensions when refactoring #45678

Closed realh closed 6 months ago

realh commented 3 years ago

Bug Report

πŸ”Ž Search Terms

importModuleSpecifierEnding Import Module Specifier Ending

πŸ•— Version & Regression Information

I've confirmed this in TS 3.9.7 (installed by npm) and 4.4.2 (Arch Linux package).

⏯ Playground Link

Sorry, I don't know how I could reproduce this outside of VS Code.

πŸ’» Code

// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

πŸ™ Actual behavior

I have "typescript.preferences.importModuleSpecifierEnding": "js" in my settings. I renamed a project folder in VS Code (using F2 in the Linux version), then clicked Yes to refactor all the other TS code that imported from that folder, using ".js" extensions. The folder was renamed successfully for each import, but they were all given a second ".js" extension, ie they were renamed to "*.js.js".

πŸ™‚ Expected behavior

The additional ".js" shouldn't have been added where one was already present.

9inpachi commented 3 years ago

Seems to work fine on the Windows verson of VSCode with TypeScript@4.2.3.

tylerbrostrom commented 3 years ago

Can confirm. Alsoβ€”and this may be unique to my setupβ€”the end quotation is removed from the specifier whenever this issue occurs.

gabritto commented 1 year ago

Can't seem to reproduce this anymore, even using TS 3.9.7 with a newer vscode (1.74.2). πŸ˜•