简体   繁体   中英

JSDoc/ESLint Reporting "Unresolved variable or type" in WebStorm

I'm encountering an odd issue with some ESLint reporting in a JavaScript file. I added some JSDoc definitions like the following:

/**
 * @typedef {Object} CustomRefA
 * @property {string} attr1
 * @property {string} attr2
 * @property {Boolean} attr3
 * @property {number} attr4
 */

/**
 * @typedef {Object} CustomRefB
 * @property {string} attr5
 * @property {string} attr6
 * @property {Boolean} attr7
 * @property {CustomRefA} attr8
 */

These definitions also get used for declaring return values from functions like this:

/**
 *
 * @param {Object} params
 * @param {string} params.attrA
 * @param {string} params.attrB
 * @returns {CustomRefA}
 */
function doesSomeActionA(options) {
    return { };
}

/**
 *
 * @param {Object} params
 * @param {string} params.attrA
 * @param {CustomRefA} params.attrB
 * @returns {Object}
 */
function doesSomeActionB(params) {
    return { };
}

What I can't quite figure out, though, is why when CustomRefA is referenced ESLint reports back with:

Unresolved variable or type 'CustomRefA'

This is also causing references to attributes of any objects assigned with the custom types to be reported back as unresolved, too. This doesn't seem to happen all the time, and I haven't been able find any info to indicate any differences between projects that could explain the issue.

For reference this is in WebStorm 2021.2, with what appears to be ESLint version 7.32.0 (according to Node/NPM). And I have done quite a bit of searching on this, but haven't been able to find much in the way of results that sufficiently applied to the situation.

Are you using a scratchpad? I was having this exact issue, and still can reproduce it in a sandbox, but if i move the code over to a file in the project directory the "Unresolved variable or type 'CustomRefA'" message goes away and the file doesn't report any problems.

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