假设我有这段代码:
/** @type {string} */
const foo = '123';
const bar = foo.map((c) => c + 1);
然后我想让 ESLint 告诉我这里有一个错误:map is not a function of a string type
我使用 WebStorm 作为我的 IDE,它可以识别问题,但我希望能够从命令行使用我的 linter 来识别这些问题。
最佳答案
ESLint 不会这样做,但可以使用 Typescript 检查 javascript 文件,而不仅仅是 typescript 文件:https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files
它支持相当多的 JSDoc 注释:https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript + 它在没有明确定义的情况下推断类型。
这是我的一个 javascript 项目的 Typescript 配置:https://github.com/voxpelli/node-promised-retry/blob/67512edc4f414d128279f25268d860d9f10d2be0/tsconfig.json
关于javascript - ESLint 解析和验证 JSDoc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53377497/