Skip to content

importModuleSpecifierEnding = js doesn't apply for autocomplete within import paths聽#44374

Description

@Tyriar

Bug Report

I have this workspace setting which works great for auto import:

"typescript.preferences.importModuleSpecifierEnding": "js"

But when auto completing the path it still does .ts which requires manually changing:

image

馃攷 Search Terms

importModuleSpecifierEnding

馃晽 Version & Regression Information

4.3.0-dev.20210503

Activity

  1. jessetrinity commented on Jun 11, 2021

    @jessetrinity
    Contributor

    Do you have

    {
        "compilerOptions": {
            "allowJs": true
        }
    }
    

    ?
    edit: see https://www.typescriptlang.org/tsconfig#allowJs. We probably need something to indicate that you need to set allowJs to actually get the .js imports.

  2. Tyriar commented on Jun 12, 2021

    @Tyriar
    ContributorAuthor

    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 allowJS for this to work when I've said I want to use .js imports already with importModuleSpecifierEnding?

  3. jessetrinity commented on Jun 14, 2021

    @jessetrinity
    Contributor

    Importing a .js file should not be allowed at all if allowJs is not enabled, so files with a .js extension 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 .ts file,

    myConst

    You should not be offered a completion at all. If you enable allowJs, this should auto complete to the .js file assuming you have "typescript.preferences.importModuleSpecifierEnding": "js".

    What I think is a bug, is that we complete with the .ts ending when there is also a .ts file with the same name present. It looks like the importModuleSpecifierEnding setting is just used to decide whether or not we remove the extension on string literal completion in the import. If allowJs is false, the .js import is not found, but we still offer the completion for the .ts file 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 .js extension even if allowJs is false, if there is a .ts file present with the same name. I'm no longer sure if it is intended behavior or not to offer import completions with .js with allowJs: false...

  4. Tyriar commented on Jun 15, 2021

    @Tyriar
    ContributorAuthor

    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.

  5. andrewbranch commented on Jun 15, 2021

    @andrewbranch
    Member

    Auto imports are working correctly and these path completions are working incorrectly. You鈥檙e never allowed to write .ts in a module specifier. You are always allowed to write a module specifier for a TS file as a .js path, and you are allowed to write an import for an actual JS source file only if allowJs is enabled. The example shown here is for a TS source file, so the completion should be shown as number.js regardless of the allowJs setting.

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: LS: Completion ListsThe issue relates to showing completion lists in an editorFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions