-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
Search Terms
"auto import", "completion", "auto import global", "auto import cache"
Suggestion
Hi, first of all good job for your awesome work.
My suggestion is simple :
When the completion is triggered, we filter the results to exclude the ones that are not importable. As you can see in
| if (sourceFile === undefined || sourceFile !== from && isImportablePath(from.fileName, sourceFile.fileName)) { |
However in some cases we want symbols that are not directly importable.
For example, if a JavaScript dependency doesn't include a
.d.ts file, and there is one available in the TypeScript cache folder (downloaded by VSCode Automatic Type Acquisition).
I think this would fix a lot of users issues.
For example : #29039
Use Cases
This would permit, to auto import the symbols from a JavaScript package that does not include a .d.ts in his sources.
For example : react-redux, lodash.
Examples
I commented the code inside isImportablePath to have a hacky prototype.
This looks like this :

But a better version would be this (I simply copied the d.ts from the global cache to the node_modules) :

Today it looks like this (you can reproduce it creating a JavaScript project and installing react-redux) :

Checklist
My suggestion meets these guidelines:
- 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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.