-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Typescript import statements #818
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
Comments
Should this be a quick fix proposal? |
apologies about this. I guess its not. Kindly move to the appropriate area as required. Or let me know if this is something I can do myself. |
@activebiz No worries, you filed the issue in the right spot. I was suggesting a solution to @dbaeumer :) |
Nice 1 :) |
Since this isn't implemented, is there a better way than having to manually find out how to navigate to the file and typing in the import statement by hand? |
We are really interested in that question as well. I have scoured the web and tried various IDEs but seems like Webstorm is the only one that supports this. Would be really nice if VSCode supported it. How do folks at Microsoft writing lots of Typescript code manage their imports? |
+1. I use this feature in WebStorm but really want to work only in VSCode |
There is already an issue in the typescript repo for this and it is scheduled for the 2.0 release. |
Closing as a dupe of microsoft/TypeScript#188 |
@egamma - just for clarity, if the linked issue gets implemented, VS Code will automatically get it as well? This is feature is one the main reasons I still use WebStorm over VS Code. |
this is correct, the completion list shown in VS Code are computed by the TypeScript server that also supports JavaScript. |
@egamma Are you referring to only auto-completing as you type import statements? That would be somewhat useful, but the most import thing for me is that if vscode autocompletes a reference to something that is not in scope where it autocompletes, then it adds an import statement to the top of the file for it. I don't feel like I should ever have to type an import statement by hand, with autocomplete help or not. |
Agree with @caseyhoward on automatically adding import statements to the top of the file. That's what I was referring to also in my previous comment. Webstorm currently does. |
Funny thing is even the Vim plugin seems to do this 😄 |
@egamma I think you've misunderstood the feature request. From the issue description:
I don't think this is implemented by the TypeScript language service, which supplies autocomplete hints but AFAIK doesn't do anything to modify the source file. Could this please be reopened? |
@masaeedu apologies if I misunderstood you. We have actually enriched the language API in 1.5 so that the language service cannot only provide a single completion but also a set of edits. See https://code.visualstudio.com/updates/v1_5#_extension-authoring the section 'powerful completion items'. We have added this so that this feature can be provided by the C# language service. The same will eventually happen in the TypeScript language service. |
That is amazing news! The issue you linked to however (microsoft/TypeScript#188), is not quite what is being asked for. The feature being requested there is better autocomplete while you are writing an import statement. This feature is about not having to explicitly write the import statement at all. The requested feature is the ability to reference any top level export from any resolvable module (without explicitly importing it), and have the appropriate import statement inserted at the top of the file. This feature can be found in WebStorm, as well as in the Roslyn compilers. See for example: It would be a huge productivity boost to have something like this in VS Code (or even better, in the language service!). I can confirm that with Visual Studio Code 1.5.3 pointing to tssdk v 2.0.3, I don't see any suggestions for generating an import statement if I reference a top level export from a module I haven't imported yet. E.g. if I install rxjs, don't import it at the top of the file, and try to reference |
It is possible that you would need some work on the part of module authors to advertise which of their exports should be advertised for auto-import in this way. |
isn't that what the concept of 'export' is all about - exporting something so that others can 'import' it? |
I'm confused this is closed. As mentioned, the issue referenced for closing this as a duplicate does not seem to mention automatically creating an import statement in its description. I installed some of the third party auto import VS Code plugins. None seemed to handle the case I was attempting, auto import statement for a decorator, but WebStorm could. It seems this should either be re-opened or labelled as not an accepted feature. |
This is indeed not a dup of microsoft/TypeScript#188. @waderyan we need to check with TS if they have a feature request for this. What people at the end of the day want is something like this:
|
I think we're looking for something like this - microsoft/TypeScript#7849 @bowdenk7 - do you know of a better duplicate in TS's repo then the one I posted above? |
@waderyan microsoft/TypeScript#7849 is what we are looking for. |
Great. Leaving this open on our end to track the completion of the work. |
This and a more advanced git integration (like WebStorm also provides) are the only 2 reasons to why I still use WebStorm instead of VScode. Not sue which one would be more important than the other... I guess this automatic import issue, even if not by much. |
This plugin seems to solve this for me. This plugin currently has everything I need. I don't think it was mentioned here before. |
Probably this was done in the last release. |
I dont think its fully supported. We need to type the whole class & then the quickfix can import. @waderyan Is this a correct observation? |
Currently the import file names are always enclosed in double quotes |
VSCode auto imports, Linters warns, I do a manual fix. It would be really great to be able to provide quote option through settings. |
There are similar problems w/ alphabetical ordering of things using tslint's "ordered-imports" feature. |
Funny thing is it imports angular |
The type of quote used for imports is tracked by microsoft/TypeScript#13270 Sorting imports is being tracked by microsoft/TypeScript#10020 Closing this issue as the original feature has been implemented. If you run into any bugs with the import quick fix or have any feature suggestions around import, please open new issues. Thanks |
As @adyavanapalli very well mentioned, you can edit the typescript.json file to get around this issue on Thx buddy. |
For import statement in typescript it would be nice if we can reference an object in a class (for e,g.) and the IDE can write (when you click on the object reference Foo in example below) an import statement for you.
For e.g.
import {Foo} from "../../../bar/somelongpath/foo"
export class Test {
private f: Foo;
}
Webstorm already provides this and it makes a lot of difference (productivitywise) as you dont have to manually type and figure out the path to the import statement.
The text was updated successfully, but these errors were encountered: