简体   繁体   中英

Webstorm - Unresolved Variable on indirectly assigned variable. How to fix with jsdoc?

I have a CONST object that holds all my constants.

To set a constant, I have a function setConst(), that adds a new key to the CONST object, if it doesn't exist.

However, Webstorm can't track these variables. I'm trying to resolve it, by using jsDoc, but can't seem to find the right code. Here is what I have tried:

/**
 * @name MY_CONST
 * @param CONST.MY_CONST
 * @type {String}
 * @memberOf CONST
 */

setConst('MY_CONST', 'hello');

//Using MY_CONST here throws an Unresolved Variable in Webstorm
MyFunction.prototype[CONST.MY_CONST] = function() {...}

function setConst(key, value) {
    if(CONST[key]) {
        throw "Key " + key + " already exists in CONST";
    }

    CONST[key] = value;
}

Can you fix this with jsDoc? Or do I just have to accept the unresolved variable errors?

Found the right jsDoc combination - here it is:

/**
 * @prop CONST.MY_CONST
 * @type {String}
 * @memberOf CONST
 */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM