Enable Go to Implementation in Typescript Editors
Could you provide a way for Typescript Editors to list the implementations of a type? This would definitely help developer productivity to be able to find implementations of types faster.
For example, in the Atom Editor atom-typescript plugin you can press F12 to 'Go to Declaration' which as currently implemented you often arrive at the typescript .d.ts file which has the function signature but not the actual implementation.
Since the Typescript parser often generates the d.ts files from the .ts implementation files. Could that association between the d.ts and .ts files be preserved (perhaps output with a typescript compiler option) so that Typescript editors could take developers to a list of the implementing classes or functions?
I opened a similar request for the Atom-typescript editor, but they indicate that they cannot implement this without Typescript parser support: TypeStrong/atom-typescript#790
So you want this functionality to jump to the corresponding .js if available, provided that the definition is ambient, correct?
@RyanCavanaugh @mousetraps @bowdenk7
So you want this functionality to jump to the corresponding .js if available, provided that the definition is ambient, correct? Yes this is a scenario that would be very useful for productivity. This alone would be very valuable. I believe the atom-typescript author believes more hooks in the Typescript compiler would make it easier for him to implement this. I'm unclear on whether this is information on js implementation line numbers is information the typescript compiler would typically know internally.
In addition, another scenario would be enabling a jump to the original typescript .ts file definition in the library being used by the application. I would imagine this information is available pre-compile to d.ts and .js files. We now have entire sets of libraries being written in .ts files as source outputting ES5 syntax js. It would be nice to achieve the ability to jump to the original typescript implementation definition in the .ts files.
I'm aware this is asking even more to jump to the .ts file implementation in the required library as it might need source map usage or distribution of source/link to original ts source. It would seem to me that the typescript compiler that generates the initial library of functions and classes would know the lines where the implementation is at and could preserve the line numbers when the library is distributed somehow so that the typscript compiler of the application using the class could know what line to jump to in the library.
Is this information on line number of implementing function/class available in source maps? Are there other sources of this information?
Given that we are going to be using the --allowJS flag, the language service should be able to work with the JS files.
I don't know how .d.ts files and .js files currently work together in that respect. @sheetalkamat probably (definitely) knows more about this than I do.
Reopening, because going to js files isn't supported quite yet
Any updates on this one? The current state of typescript is that you cannot jump to the implementation of code in many prominent libraries.
This issue has been moved/closed/duped/deduped multiple times and fixing this bug could be a huge productivity boost.
https://github.com/ubershmekel/vscode-ts-goto-source has a project that reproduces the issue. As explained in https://github.com/Microsoft/vscode/issues/26325 and referenced in https://github.com/Microsoft/vscode/issues/10806 and https://github.com/Microsoft/vscode/issues/18321
Note I had to use "typescript.disableAutomaticTypeAcquisition": true from one point to use the javascript "go to definition" because it seems the .d.ts files take over if found.
@DanielRosenwasser Any updates on this? - Single most wanted feature for me.
This is particularily annoying if working in a monorepo written entirely in Typescript. I have multiple times when adding a field to a type or similar smaller changes used "go to definition", added it and then later found it missing again realizing that I added it to the .d.ts file and not the actual .ts file
@DanielRosenwasser Is this progressing? I would really love this feature
same issue. Want to "Go to implementation" to the source code, not xx.d.ts
Yep, multiple times a day I by mistake edit the declaration file after using cmd+click and end up confused when the code doesn't run correctly. Especially since src and dec look very similar. Would be awesome if there was some way to choose if I want to go to source of declaration, or even better if VSCode would figure this out as going to source is always more preferable IMHO (if it is available).
going to source is always more preferable IMHO (if it is available)
When the source is in TS. If the source is in JS though there's a good reason to go to the .d.ts
When the source is in TS. If the source is in JS though there's a good reason to go to the .d.ts
Why? I can just hover to see the type definition. Anyway, there should be a separate command for type definition vs implementation.
Is there any reason why this is still pending? A workaround, alternative or something? Thanks in advance
Since the Typescript parser often generates the d.ts files from the .ts implementation files. Could that association between the d.ts and .ts files be preserved (perhaps output with a typescript compiler option) so that Typescript editors could take developers to a list of the implementing classes or functions?
I have a branch of #21930 that enables producing precisely these declaration file sourcemaps (and will have that out for review either on request or once #21930 is merged), and am working on adding support into our LS for following these maps. We want to ship it in 2.8.
So yeah, we've been working on it. It just needed a lot of internal changes. 😄
Expect updates on this issue to relieve the pain on finding implementations through manually expand folders under node_modules and locate the entry module file.
Is there any workaround for this? As we have a big module for our db queries written in ts it would be really nice to see the real source code with one command instead of searching through the node_modules.
@derN3rd There is vscode-search-node-modules extension to browse node_modules in the command panel (and I also have a fork which always opens README vscode-open-node-modules)
I understand it's far from the perfect ux to click on require/import and open source a file, but definitely better than scrolling node_modules
@derN3rd we will be shipping a --declaratrionMap flag in 2.9 (which may be released during next month), and we've already enabled going to definitions in the original source TS over an associated .d.ts using them (which, if you're shipping declaration files in your node modules folder may get a lot of what you want). We're also looking into jumping to/from the associated JS as well, provided normal sourcemaps are also on.
@weswigham thanks for the fast reply! Sounds good Could you post an update here if the feature is ready or ready to be tested?