WebStorm and TypeScript: how to go to the source JS package file?

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

response.send('Hello'); 

I want to see how the send() method is implemented. However, when I ctrl + click on the method name in WebStorm, it will lead me to the .d.ts file (TypeScript definition) instead of the real source. Understood, but a little unpleasant. What is the easiest way to get to the source?

+6
source share
1 answer

The easiest way to get to the source is to disable the appropriate library (if the d.ts files were loaded as a library) / delete typescript definitions from the project. WebStorm will then try to find the definition in the .js files.

There is a function request for the ability to "combine" typescript definitions with available .js definitions, using d.ts to complete and .js to navigate ( WEB-12630 ). The only problem is that WebStorm cannot always find the correct definition in .js - and that is the reason for using typescript definitions. For example, if module properties are determined by iterating files in the 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); }); 

Allow them to complete / navigate is not possible

+2
source

Source: https://habr.com/ru/post/1012632/


All Articles