Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint to parse and verify JSDoc

Say I have this piece of code:

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

Then I'd like ESLint to tell me I've got an error here: map is not a function of a string type

I use WebStorm as my IDE and it recognizes the issue, but I'd like to be able to recognize these issues using my linter from the command line.

like image 553
YardenST Avatar asked Oct 20 '25 12:10

YardenST


1 Answers

ESLint does not do this, but one can check javascript files, not just typescript files, with Typescript: https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files

It supports quite a few JSDoc comments: https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript + it infers types when nothing has been explicitly defined.

Here's the Typescript config of an javascript project of mine: https://github.com/voxpelli/node-promised-retry/blob/67512edc4f414d128279f25268d860d9f10d2be0/tsconfig.json

like image 122
VoxPelli Avatar answered Oct 22 '25 00:10

VoxPelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!