ESLint 解析和验证 JSDoc

ESLint to parse and verify JSDoc

假设我有这段代码:

/** @type {string} */
const foo = '123';
const bar = foo.map((c) => c + 1);

然后我想让 ESLint 告诉我这里有一个错误:map 不是字符串类型的函数

我使用 WebStorm 作为我的 IDE 并且它识别出了这个问题,但我希望能够从命令行使用我的 linter 识别这些问题。

ESLint 不会这样做,但可以检查 javascript 文件,而不仅仅是打字稿文件,使用打字稿: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