-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
π Search Terms
importScripts import imports ESM
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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.
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
importstatement suggestion is always place ahead ofimportScripts(β¦). - Prevent
importScriptsfrom 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
- What do you want to use this for?
Any time I import anything in any JS/TS file.
- 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.
- What workarounds are you using in the meantime?
I've investigated a bunch, and I'm not aware of any other workarounds.
