Repository navigation
importModuleSpecifierEnding = js doesn't apply for autocomplete within import paths聽#44374
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScript
on Jun 2, 2021 - addedDomain: LS: Completion ListsThe issue relates to showing completion lists in an editorThe issue relates to showing completion lists in an editor
on Jun 2, 2021 - added this to the TypeScript 4.4.0 (Beta) milestone
on Jun 2, 2021 jessetrinity commented
on Jun 11, 2021 ContributorMore actionsDo you have
{ "compilerOptions": { "allowJs": true } }?
edit: see https://www.typescriptlang.org/tsconfig#allowJs. We probably need something to indicate that you need to setallowJsto actually get the.jsimports.No I don't set that, I can't actually remember why I ended up needing to use .js imports but at some point this not having it was causing exceptions due to some bundling problem. I just tried to remove and it seemed to work, I'm a little hesitant to change it when it working though.
But why would you need
allowJSfor this to work when I've said I want to use .js imports already withimportModuleSpecifierEnding?jessetrinity commented
on Jun 14, 2021 ContributorMore actionsImporting a
.jsfile should not be allowed at all ifallowJsis not enabled, so files with a.jsextension will not show up in the completion list.That is, if you have
allowJs: false(this is the default) and the file// file: myLib.js export const myConst = 1;
and type the following in a
.tsfile,myConstYou should not be offered a completion at all. If you enable
allowJs, this should auto complete to the.jsfile assuming you have"typescript.preferences.importModuleSpecifierEnding": "js".What I think is a bug, is that we complete with the
.tsending when there is also a.tsfile with the same name present. It looks like theimportModuleSpecifierEndingsetting is just used to decide whether or not we remove the extension on string literal completion in the import. IfallowJsis false, the.jsimport is not found, but we still offer the completion for the.tsfile with the same name, but with the extension (incorrectly) attached. I think in this case we should offer the completion without any extension.cc Andrew Branch (@andrewbranch) as I'm not super familiar with how module resolution works.
Edit: after more investigation I see that auto import completion (not import string completion) adds the
.jsextension even ifallowJsis false, if there is a.tsfile present with the same name. I'm no longer sure if it is intended behavior or not to offer import completions with.jswithallowJs: false...I can't remember the exact reason but using .js fixed a compile/bundling issue for me at some point. I use tsc and then webpack on its output, could be related to workers, dynamic imports or es modules.
andrewbranch commented
on Jun 15, 2021 MemberMore actionsAuto imports are working correctly and these path completions are working incorrectly. You鈥檙e never allowed to write
.tsin a module specifier. You are always allowed to write a module specifier for a TS file as a.jspath, and you are allowed to write an import for an actual JS source file only ifallowJsis enabled. The example shown here is for a TS source file, so the completion should be shown asnumber.jsregardless of theallowJssetting.Reacted by Daniel Imms, Jesse Trinity and Gabriel Bider- addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Jun 15, 2021 - locked as resolved and limited conversation to collaborators
on Oct 21, 2025
Bug Report
I have this workspace setting which works great for auto import:
But when auto completing the path it still does .ts which requires manually changing:
馃攷 Search Terms
importModuleSpecifierEnding
馃晽 Version & Regression Information
4.3.0-dev.20210503