简体   繁体   English

JSDoc/ESLint 在 WebStorm 中报告“未解析的变量或类型”

[英]JSDoc/ESLint Reporting "Unresolved variable or type" in WebStorm

I'm encountering an odd issue with some ESLint reporting in a JavaScript file.我在 JavaScript 文件中遇到了一些 ESLint 报告的奇怪问题。 I added some JSDoc definitions like the following:我添加了一些 JSDoc 定义,如下所示:

/**
 * @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:不过,我不太明白的是,为什么当引用CustomRefA时,ESLint 会返回:

Unresolved variable or type 'CustomRefA'未解析的变量或类型“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).作为参考,这是在 WebStorm 2021.2 中,似乎是 ESLint 版本 7.32.0(根据 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.我遇到了这个确切的问题,并且仍然可以在沙箱中重现它,但是如果我将代码移到项目目录中的文件中,“未解析的变量或类型'CustomRefA'”消息消失并且文件不报告任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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