Skip to content

Global completion / Auto import for JavaScript symbols from modules without typings included. #33289

Closed
@g3offrey

Description

@g3offrey

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 :
Kapture 2019-09-06 at 23 03 55
But a better version would be this (I simply copied the d.ts from the global cache to the node_modules) :
Kapture 2019-09-06 at 23 10 50
Today it looks like this (you can reproduce it creating a JavaScript project and installing react-redux) :
Kapture 2019-09-06 at 23 07 06

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix 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