如何使WebStorm解析哪些功能? [英] How to make WebStorm resolve modules which are functions?

查看:158
本文介绍了如何使WebStorm解析哪些功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebStorm在解析从CommonJS模块作为方法返回的函数方面做得非常好(并读取与它们相关的JsDoc),例如:

WebStorm does a very good job of resolving functions which are returned from CommonJS modules as methods (and reads JsDoc associated with them), like for instance:

// utils/valid.js
/**
 * Returns true no matter what.
 * @param {HTMLElement} element
 * @return {boolean}
 */
function isValid(element) {
    return true;
}
module.exports.isValid = isValid; // exports property

然后在代码完成内联文档机制,当在另一个文件中需要这样的模块时。

Such a function is then correctly provided in code completion and inline documentation mechanisms when such a module is required in another file.

// main.js
var isValid = require('./utils/isValid').isValid; // works well

但是,当函数作为模块导出直接返回时,这会失败

However, this fails when the function is returned directly as module exports

// utils/valid.js
module.exports = isValid; // exports object is a function

所以当需要这样的模块时,WebStorm似乎不知道是什么它是:

So when such a module is required, WebStorm seems to not know what it is:

// main.js
var isValid = require('./utils/isValid'); // doesn't work

这在我们的项目中很常见并且更改了所有 module.exports 到普通对象不是一个选项。有没有办法在WebStorm中解决这个问题?

This is very common in our project and changing all module.exports to plain objects is not an option. Is there any way for fix this issue in WebStorm?

推荐答案

创建一个宏来在两种语义形式之间切换:

Create a macro to switch between the two semantic forms:

<iframe width="854" height="480" src="https://www.youtube.com/embed/J3YX1WIScAk" frameborder="0" allowfullscreen></iframe>

参考

Komodo Edit autocompletion JS object literal

这篇关于如何使WebStorm解析哪些功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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