Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm and TypeScript: how to navigate to JS source file of a package?

Say that in my TypeScript project, I use Express and a method like this:

response.send('Hello');

I want to look how the send() method is implemented. However, when I ctrl+click the method name in WebStorm, it takes me to a .d.ts file (TypeScript definitions) instead of the real source. Understandably but a bit unpleasantly. What's the easiest way to get to the source?

like image 321
Borek Bernard Avatar asked Nov 24 '16 13:11

Borek Bernard


People also ask

How do I navigate in WebStorm?

Navigate to a file with the Navigation bar Use the Navigation bar as a handy tool to find your way across the project. Press Alt+Home to activate the Navigation bar. Use the arrow keys or the mouse pointer to locate the desired file.

Does WebStorm work with TypeScript?

With WebStorm, you can run and debug client-side TypeScript code and TypeScript code running in Node. js. Learn more from Running and debugging TypeScript.


1 Answers

The easiest way to get to the source is disabling the corresponding library (if d.ts files were downloaded as a library)/removing typescript definitions from project. Then WebStorm will try to find the definition in .js files.

There is a feature request for a possibility to 'merge' TypeScript definitions with available .js definitions, using d.ts for completion and .js - for navigation (WEB-12630). The only problem here is that WebStorm can't always find the correct definition in .js - and that's the reason for using TypeScript definitions instead. For example, if the module properties are defined by iterating files in file system:

fs.readdirSync(__dirname + '/middleware').forEach(function(filename){
  if (!/\.js$/.test(filename)) return;
  var name = basename(filename, '.js');
  function load(){ return require('./middleware/' + name); }
  exports.middleware.__defineGetter__(name, load);
  exports.__defineGetter__(name, load);
});

Resolving them for completion/navigation doesn't seem to be possible

like image 126
lena Avatar answered Sep 27 '22 21:09

lena