WebStorm 和 TypeScript:如何导航到包的 JS 源文件? [英] WebStorm and TypeScript: how to navigate to JS source file of a package?

查看:48
本文介绍了WebStorm 和 TypeScript:如何导航到包的 JS 源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在我的 TypeScript 项目中,我使用 Express 和这样的方法:

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

response.send('Hello');

我想看看 send() 方法是如何实现的.但是,当我在 WebStorm 中按住 ctrl+单击方法名称时,它会将我带到 .d.ts 文件(TypeScript 定义)而不是真正的源.可以理解,但有点不愉快.获取源头的最简单方法是什么?

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?

推荐答案

获取源代码的最简单方法是禁用相应的库(如果 d.ts 文件作为库下载)/从项目中删除打字稿定义.然后 WebStorm 会尝试在 .js 文件中找到定义.

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.

有一个功能要求可以将 TypeScript 定义与可用的 .js 定义合并",使用 d.ts 完成和 .js - 用于导航(WEB-12630).这里唯一的问题是 WebStorm 不能总是在 .js 中找到正确的定义——这就是使用 TypeScript 定义的原因.例如,如果模块属性是通过迭代文件系统中的文件来定义的:

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

这篇关于WebStorm 和 TypeScript:如何导航到包的 JS 源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆