Skip to content

When implements interface in typescript adds import before element #28165

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

Closed
mjbvz opened this issue Oct 26, 2018 · 14 comments
Closed

When implements interface in typescript adds import before element #28165

mjbvz opened this issue Oct 26, 2018 · 14 comments
Labels
Bug A bug in TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions.
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Oct 26, 2018

From @inferius on October 11, 2018 8:6

Hi, implements interface in typescript auto adds import with absolute path before element of class.

  • VSCode Version: 1.28.0
  • OS Version: Windows 10

Steps to Reproduce:
ezgif-1-cab6cff57ba4

Does this issue occur when all extensions are disabled?: Yes

Copied from original issue: microsoft/vscode#60606

@mjbvz mjbvz self-assigned this Oct 26, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 26, 2018

Please try upgrading your workspace to use typescript@next by following these instructions. Do you still see this error after upgrading?

@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 26, 2018

From @inferius on October 12, 2018 7:28

Yes, i still see this error after upgrading.

@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 26, 2018

Thanks for testing. Can you please share your tsconfig and a basic description of your project structure

@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 26, 2018

From @DanTup on October 23, 2018 9:3

@mjbvz I see this too. I've pushed a branch with a repro here:

https://github.com/Dart-Code/Dart-Code/tree/vscode-60606-repro

Clone the vscode-60606-repro branch, open src/pub/pub_task_provider.ts and then use the quick-fix to implement the interface. I changed it to typescript@latest and see the same issue.

screen shot 2018-10-23 at 9 57 51 am

screen shot 2018-10-23 at 9 57 56 am

screen shot 2018-10-23 at 10 03 01 am

(using * as vs in the import correctly puts vs. prefixes instead of import calls).

@mjbvz mjbvz removed the typescript label Oct 26, 2018
@mjbvz mjbvz removed their assignment Oct 26, 2018
@weswigham weswigham added Domain: Quick Fixes Editor-provided fixes, often called code actions. Experience Enhancement Noncontroversial enhancements labels Oct 26, 2018
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript and removed Experience Enhancement Noncontroversial enhancements labels Oct 31, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.3 milestone Oct 31, 2018
@weswigham weswigham unassigned ghost Dec 13, 2018
@MeirionHughes
Copy link

Any update on this? just seems to have been kicked into the long grass.

@weswigham
Copy link
Member

We'd probably take PRs to fix it ❤️

@mjbates7
Copy link

Still occurring - running insiders 1.38.0 build. Any updates or thoughts? It's generating code like this: (angular)

image

@weswigham
Copy link
Member

That code is technically equivalent to the version where an import statement is used, just not as pretty - hence why this hasn't been the highest priority for us, and why I said we'd take a PR to fix it~ ❤️

@keotl
Copy link

keotl commented Aug 28, 2019

I opened a PR which forces private aliases for implemented interface types. However, pointers would be appreciated for adding automatic importation.

giphy

@weswigham
Copy link
Member

You'd want to query for the same type nodes that we do today (complete with import types), but then traverse the node tree looking for instances of ImportTypeNodes, and transform them into a normal type reference by replacing the import(...) part with a generated name, and then adding an import * as generatedName from "..." statement. Then you can get smarter, like using named imports rather than namespace, and merging with existing import statements where possible.

@keotl
Copy link

keotl commented Aug 30, 2019

I pushed a new version with automatic imports.
giphy
This would be ready for review/testing.

@JulianLang
Copy link

So, what's the status here?

@avol-io
Copy link

avol-io commented Mar 2, 2020

any news?

@andrewbranch
Copy link
Member

This was fixed by #36615 which is included in TypeScript 3.8.

Unfortunately, #34995, the issue I was assigned, was never marked as a duplicate of this one, and so I was never aware of the existence of this issue or the great work by @keotl at #33126. Sadly this happens from time to time in a repo with thousands of issues, but my apologies for the mixup nonetheless, particularly to @keotl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants