TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Enable Go to Implementation in Typescript Editors

Open doliver3 opened this issue 10 years ago • 133 comments

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

doliver3 avatar Dec 22 '15 20:12 doliver3

This is really crucial. I want simple thing: CTLR+Click and navigate to node_modules/library/source.js or source.ts file. Opensource project with 60 node_modules dependencies and you are back to using notepad with explorer.

cyberluke avatar Oct 16 '19 13:10 cyberluke

When I right-clicked on a component I saw: "Go to Definition" and "Go to Type Definition". I thought "Great, this has been well designed, the solution to my problem is just here!". Then I clicked on "Go to Definition" and... landed to the Type Definition.

cvolant avatar Oct 29 '19 09:10 cvolant

This is really crucial. I want simple thing: CTLR+Click and navigate to node_modules/library/source.js or source.ts file. Opensource project with 60 node_modules dependencies and you are back to using notepad with explorer.

+1 Same need.

snayam avatar Dec 17 '19 23:12 snayam

With all due respect, the fact that this isn't implemented is incredible. Such a basic, relatively easy to build feature that would save people tons of time.

andrestone avatar Feb 23 '20 12:02 andrestone

With all due respect, the fact that this isn't implemented is incredible. Such a basic, relatively easy to build feature that would save people tons of time.

+1

or2008 avatar Feb 23 '20 12:02 or2008

Well, in the meantime when this feature is not yet available, is there any better workaround beside searching for the whole node_modules ? It really inconvenience... For example, I go to the definition and it led me to node_modules/@com.abc/sample/lib/core/internal/abc.d.ts when the one I want is actually located at node_modules/@com.abc/sample/src/core/internal/abc.ts

trungklam avatar Mar 10 '20 03:03 trungklam

@Happin3ss

is there any better workaround beside searching for the whole node_modules ?

The current solution AFAIK is declaration maps. These are sourcemaps that map .d.ts files to the corresponding TS source. If you can convince the libraries that you depend on to implement declaration maps (which I think effectively requires publishing .d.ts inside the library package as opposed to relying on @types) then you'll be able to automatically jump from your client code to the original TS (or even JS if using the TS compiler on JS?) source code.

What I've been doing is gradually filing PRs against my most important dependencies (at least the ones that are authored in TS) to get them to add declaration maps.

Obviously it'd be better if changing the library weren't required.

Another workaround (if changing the library isn't possible) works in the case where the library bundles .d.ts inside the package but doesn't have declaration maps. In that case, I'll use Go To Definition to get to the type declaration, then I'll click the Explorer button in VSCode to show the folder sidebar. That usually gets me very close to the src folder for the package, so instead of having to search through all of node_modules, I can just browse into the right folder and open the correct file. This is dependent on clear file naming, etc. and is not a panacea.

Just to be 100% clear-- I'd love to see a better solution for libraries, esp. those where .d.ts is authored separately from the package.

justingrant avatar Mar 10 '20 03:03 justingrant

Not sure if I've missed it, but it would be really useful for understanding what's happening to have actual minimal examples of sources, declarations and declaration maps. I've never seen either Go to Definition, Go to Type Definition, or Go to Implementations actually go to anything but a .d.ts file for transpiled TS. I just tried to make a simple example, and it doesn't work; I can't get VS Code to go to anything but the .d.ts file, even though the .d.ts.map is next to it. I've also found someone else with the same issue who was ignored.

It's understandable that supporting external typings like @types would be hard, but what does it say that even the "happy path" can't be made to work?

There are many libraries that generate declaration files but not declaration maps, and it's unclear what the argument would be for enabling them. This option has been added without a clear explanation, at least one that I'd be able to find.

slikts avatar Mar 10 '20 05:03 slikts

Yes, I confirm that declaration maps are not solving the problem. My project has got declaration maps but vscode does not navigate beyond .d.ts files.

avkonst avatar Mar 10 '20 11:03 avkonst

It sure would be great if this happened.

zachweinberg avatar Apr 09 '20 22:04 zachweinberg

if there is an "elephant in the room" of issues for ms vscode devs, this is it.

russeg avatar May 20 '20 13:05 russeg

Any updates on this one? I just decided to make a big step: move from JS to TS. I thought - "what am I doing wrong?" but actually, it's unexpected behavior of VSCode

belykh avatar May 22 '20 21:05 belykh

Any updates on this one? I just decided to make a big step: move from JS to TS. I thought - "what am I doing wrong?" but actually, it's unexpected behavior of VSCode

It was a long history since this behavior had been raised. Well, nothing going on here. No plan so far. For me, I keep using vscode as a kind of editor as it is, and Intellij products (IDEA) for my coding stuffs even I don't like it so much.

trungklam avatar May 23 '20 10:05 trungklam

Opened for 5 years, hope it will be fixed in 2025

yzevm avatar Jul 20 '20 13:07 yzevm

I've created failing tests in #39426 but I don't know how to implement it

sheerun avatar Jul 20 '20 14:07 sheerun

Just another miserable comment from ts dev going through hell everyday to find definitions

sb-bilal-dev avatar Aug 09 '20 21:08 sb-bilal-dev

This is crazy... I thought I was just a TS noob, but now I see that the behavior I’m getting is actually “standard”???? So frustrating, every other IDE/language I’ve used has this implemented at initial release... :( I love VS code but honesty this could be a deal breaker

parksj10 avatar Oct 09 '20 07:10 parksj10

Can anyone explain why go to definition/implementation features in VSCode with Python extensions for, huh, Python language works better (it's works at least) then for JS having native built-in solutions?

carpet92 avatar Oct 10 '20 02:10 carpet92

So what is going on? I am using scss.d.ts for css modules and can't jump to scss.

Also when creating simple .js and accordingly d.ts, I cannot jump straight to js

prbxr avatar Oct 26 '20 13:10 prbxr

why not use webstorm? it can solve this problem!!! my version 2020.1

xchange-api avatar Nov 03 '20 02:11 xchange-api