Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeFix for missing import should take into account main in package.json #13130

Closed
normalser opened this issue Dec 22, 2016 · 5 comments
Closed
Labels
Suggestion An idea for TypeScript

Comments

@normalser
Copy link

image

package.json of antd module:

  {//...
  "main": "lib/index.js",
   //...
  }

Files inside antd module:

...
antd/lib/index.js 
antd/lib/index.d.js
...

Ideally if import would be Import Button from "antd"

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Dec 22, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 22, 2016

We try not to do disk lockups here. disk access in general is expensive. given a module, we do not know if it is referenced in package.json higher on or not. so we have to keep walking up and probing.

@normalser
Copy link
Author

Right regarding 'disk lookups'

Although it seems like TS already knows that information:
image

I was hoping it could be reused in this case (maybe its not about main in package.json but the special case for index.d.ts and/or lib/index.d.ts

@mhegazy
Copy link
Contributor

mhegazy commented Dec 22, 2016

the module resolution is a different process. let me explain.

the compiler looks at imports in your file, and resolves them to files. this involves disk probing, etc.. it reads package.json, it looks up folders, etc.. you can see what is going on using --traceResolution.

the quickfix is trying to add an import that does not exist. so the information the compiler built during resolution is not useful here, as the import was not there.

the issue is to compute the quickfix you could have the same name coming from multiple modules. and modules could be imported through multiple names, so the only option is to repeat the process of resolution for each proposed quickfix. and we would rather not do that.

@normalser
Copy link
Author

Oh i see, thank you so much for the explanation

@mhegazy
Copy link
Contributor

mhegazy commented Apr 21, 2017

Tracking under #15223

@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants