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
--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.
Any news for that on 3.0-rc?
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;
}
VS Code now ships with TypeScript 3.0.3. Any news on this issue?
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 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 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 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
Hope can prioritize this issue, it is really a big pain, from so many comments and related issues.
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.
it's a long request
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.
This should be labeled Bug, not Suggestion.
The lack of code navigation really ruins the VSCode experience for JavaScript developers.
sorry to spam the thread but @promaty I use the search-node-modules extension 😬 for now
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!
"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.tsline 117 - "Go to Type Definition" ->
node_modules/@angular/core/testing/src/component_fixture.d.tsline 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.
We have to manually search source codes for now :/
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
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!
So that's why flow is still useful.