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

--declarationMap (and associated LS redirection) has been in our nightlies since just after the 2.8 release. The only bit we've not done yet is the JS file hopping, as that may require some extra editor coordination.

weswigham avatar Apr 19 '18 18:04 weswigham

Any news for that on 3.0-rc?

derN3rd avatar Jul 13 '18 07:07 derN3rd

Same issue with .css and .json files. Go to Definition taking me to .d.ts file.

import React from 'react'
import Route from 'react-router-dom/Route'
import Switch from 'react-router-dom/Switch'
import Loadable from 'react-loadable'
import  './App.css'
import './tailwind.css'

Go to Definition on ./App.css takes me to

declare module '*.css' {
    const content: any;
    export default content;
}

declare module '*.svg' {
    const content: any;
    export default content;
}

declare module '*.json' {
    const content: any;
    export default content;
}

SheikhG1900 avatar Aug 16 '18 17:08 SheikhG1900

VS Code now ships with TypeScript 3.0.3. Any news on this issue?

carpet92 avatar Sep 06 '18 02:09 carpet92

Works for me (declaration maps generated with TS 2.9.2, running VSCode 1.27.0). Navigating from an API consumer (implemented in JS) Go to Definition takes me to the implementation in the .ts file.

robsman avatar Sep 06 '18 07:09 robsman

@robsman Go to Definition should take you to the compiled js code, while Go to Type Definition should take you to the .d.ts file.

How do you use/include your compiled module, to open the source files?

That issue still exists for me in VSCode 1.27.0, as both functions take me to the .d.ts file

EDIT: I think I misunderstood your comment. Does it take you to the real code? If so, are you using a monorepo or is your compiled code shipped in a own npm module? Do you ship the source files with your compiled code?

derN3rd avatar Sep 06 '18 09:09 derN3rd

@derN3rd re-tested, both Go to Definition and Go to Type Definition as well as Peek Definition take me to the real code in the .ts file.

The API declaration and implementation both sit in a separate module that the calling package refers to as a git+ssh... dependency.

robsman avatar Sep 06 '18 20:09 robsman

@robsman I think Go to Definition should refer me to source of "this" class or function in source js file (if it's javascript) inside node_modules not .d.ts. Like it works in Sublime Text 3 I mean. Anyway I don't understand for what VSCode this feature in the current state

carpet92 avatar Sep 19 '18 02:09 carpet92

Hope can prioritize this issue, it is really a big pain, from so many comments and related issues.

prufeng avatar Oct 18 '18 09:10 prufeng

Please add me to the long list of folk trying to use command-click to navigate through the code. I have no TS in my project and the npm package I am navigating to does not use TS, yet command-click on require('co-body') takes me to an internally generated TS definition. I am long time IntelliJ user and still, because of this, I fall back to IntelliJ.

bartlettpsj avatar Jan 31 '19 17:01 bartlettpsj

it's a long request

chaosforfun avatar Mar 07 '19 03:03 chaosforfun

I like VS Code a lot and I just started a new Node project and decided to use TypeScript for the first time. So far so mostly good, but this issue has been a pain point. Working in open-source, the ability to click through to real source code in dependencies is vital to work-flow. I am working in TypeScript source files and using JS NPM modules with associated @types/xxx modules that have no associated documentation. IntelliSense with TypeScript is great, but doesn't always provide enough information. At the very least, being able to click straight through to the module source from the import statement would be nice. I believe on some libraries that works, and on others, e.g. Passport, I can't get past the adjunct TypeScript stubs in the @types module.

restjohn avatar Mar 29 '19 15:03 restjohn

This should be labeled Bug, not Suggestion.

The lack of code navigation really ruins the VSCode experience for JavaScript developers.

remcohaszing avatar Apr 04 '19 08:04 remcohaszing

sorry to spam the thread but @promaty I use the search-node-modules extension 😬 for now

phil-lgr avatar May 06 '19 22:05 phil-lgr

WebStorm has the same behaviour: StackOverflow, BugTracker

  • VSCode has "Go to Definition" and "Go to Type Definition" actions

  • WebStorm has "Go To Declaration" and "Go To Type Declaration" actions

But when using TypeScript, both IDEs do the same thing: always go to the type definition!

joeysino avatar May 17 '19 02:05 joeysino

"Go to Definition" and "Go to Type Definition", when used on node_modules/ libraries, both take me to .d.ts files. I'm on the latest VS Code as of writing (1.34.0).

For example: npm package @angular/[email protected], when I import TestBed from @angular/core/testing and try to see the definition of TestBed.createComponent, I get two different things:

  • "Go to Definition" -> node_modules/@angular/core/testing/src/test_bed_common.d.ts line 117
  • "Go to Type Definition" -> node_modules/@angular/core/testing/src/component_fixture.d.ts line 14

This basically means that the Angular source code is hidden from me in VS Code 😞 I'm not sure if that's a symptom of how the Angular library is written, or how TypeScript/VS Code finds source implementations.

All I know is I can only reliably use "Go to Definition" and "Go to Type Definition" on my own code, in which case I get taken directly to the source; I'm never shown a .d.ts file for my own code.

henrahmagix avatar May 17 '19 08:05 henrahmagix

We have to manually search source codes for now :/

silverqx avatar May 21 '19 11:05 silverqx

Aw, I just figure out that somehow Intellij IDEA have this function work really well, even I'm on the same project, using Typescript 3.0.1

trungklam avatar May 22 '19 07:05 trungklam

I thought the priority of this issue should be bumped up.

We have to command + , to open the workspace settings -> uncheck Use Ignore Files -> delete Search: Exclude: **/node_modules, and manually search source codes.

EVERY DAY!

kaelzhang avatar May 28 '19 03:05 kaelzhang

So that's why flow is still useful.

hushicai avatar Jun 06 '19 10:06 hushicai