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

Add missing import use package.json "typings" property #15020

Closed
mjbvz opened this issue Apr 5, 2017 · 7 comments
Closed

Add missing import use package.json "typings" property #15020

mjbvz opened this issue Apr 5, 2017 · 7 comments
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 5, 2017

From @kukjevov on April 4, 2017 18:30

  • VSCode Version: 1.10.2
  • OS Version: Windows 10

Add missing import is great feature but it does not work best way.

Lets say i have module @ng/common
in module i have package.json in root directory and index.d.ts in dist directory.

In package.json i have "typings": "dist/index.d.ts".

When i want to use this module i want to write import {Utils} from '@ng/common'; but vscode quick fix import missing import offers me different imports like this import {Utils} from '@ng/common/dist'; which is not what i want. Is it possible to make it look into package.json for obtaining these information about import? Also when i use @angular it is same. Sometimes it even offers me more options. Same things reexported from multiple files, but none exported using package.json.

Also nice thing would be if it uses shortest "path" export if some type is reexported.

I dont know if this is thing for vscode, or typescript directly.

Thank you for any help :).

Copied from original issue: microsoft/vscode#23898

@mjbvz mjbvz self-assigned this Apr 5, 2017
@mjbvz mjbvz removed their assignment Apr 5, 2017
@mjbvz mjbvz added VS Code Tracked There is a VS Code equivalent to this issue and removed typescript labels Apr 5, 2017
@mjbvz
Copy link
Contributor Author

mjbvz commented Apr 5, 2017

@kukjevov Can you please provide a small example project that demonstrates this issue?

@kukjevov
Copy link

kukjevov commented Apr 5, 2017

Hello :).

Thx for quick reaction. Here is example that illustrates what i described.

https://github.com/kukjevov/typescript-import

if you clone it and run npm install then open it in vscode you can see problem in example.ts.

In index.ts you can see what i want and how imports should look like. But for '@ng/common' in example.ts it offers me path to index.d.ts ('@ng/common/dist') even if i specified "typings" property in package.json for @ng/common module which is correctly used by typescript compiler but not by typescript import helper.

Same thing happens for '@angular/core' where they have core.d.ts in root directory, which is pointed to from package.json by "typings" property, but it is not used. In this case it is even worse, because same type is offered 4 times, but all from wrong file.

Also interesting thing that i found out, that if i dont have at least one import from '@angular/core' in some file (this time in index.ts) it does not offer me anything, not even bad import. How does it work? Does is it scan node_modules?

Just one note to this, is there going to be option to set if i want spaces around brackets in import statements?

Anyway thx for great job and any help :)

@aluanhaddad
Copy link
Contributor

I've had similar issues where package.json typings points to a top level file but the quick-fix always grabs the file from src/index because I distribute the source as part of my npm package.

@kukjevov
Copy link

kukjevov commented Apr 6, 2017

@mjbvz Have you looked at this :)? Thank you for any help :).

@mjbvz
Copy link
Contributor Author

mjbvz commented Apr 7, 2017

@kukjevov I took a look at this issue on the VSCode side but the problem seems to lie with the TypeScript server itself. That's why I moved the issue to the TypeScript repo.

A TypeScript contributor should be able to help investigate this issue

@kukjevov
Copy link

kukjevov commented Apr 9, 2017

Hello can some of Typescript team look at this, it would be nice feature :).

ping @sandersn @ahejlsberg @yuit @RyanCavanaugh

Thank you :)

@mhegazy
Copy link
Contributor

mhegazy commented May 1, 2017

tracked by #15223

@mhegazy mhegazy closed this as completed May 1, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label May 1, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

4 participants