How to make WebStorm resolve modules which are functions?

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

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

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="" frameborder="0" allowfullscreen></iframe>



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.