Skip to content

Preventing importScripts(…) (ambient declaration) from being suggested ahead of import statements.Β #62951

@lgarron

Description

@lgarron

πŸ” Search Terms

importScripts import imports ESM

βœ… Viability Checklist

⭐ Suggestion

When I type imp… into a JS project with the DOM API in VS Code, the first suggestion is always the ambient importScripts(…) function.

Image

Note that this happens in any JS/TS file, regardless of whether I'm writing web worker code. I have well over a decade of experience with web workers and I understand the historical importance of this function, but as of several years ago this suggestion is never appropriate for me.

I would like a way to either:

  • Ensure the import statement suggestion is always place ahead of importScripts(…).
  • Prevent importScripts from ever showing up as a suggestion.

πŸ“ƒ Motivating Example

This allows developers to get the suggestion for the vastly more often-used import β€” a simple ergonomic win for what might be the most widely used syntax completion in JS/TS file.

It also recognizes that importScripts has gone the way of the past. Even when writing web worker code, it's been possible to use cross-browser module workers since 2023 with vastly better ergonomics. So importScripts is essentially on the way to becoming a legacy API.

πŸ’» Use Cases

  1. What do you want to use this for?

Any time I import anything in any JS/TS file.

  1. What shortcomings exist with current approaches?

Change VS Code settings to "editor.suggestSelection": "recentlyUsed". This can kind of work, but it breaks repeatability (and therefore muscle memory) for all other import completions.

VS Code also supports javascript.preferences.autoImportSpecifierExcludeRegexes and typescript.preferences.autoImportSpecifierExcludeRegexes. These are a good precedent for being able to prevent certain suggestions, but I don't think they can help here.

  1. What workarounds are you using in the meantime?

I've investigated a bunch, and I'm not aware of any other workarounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions