MongoError warning where there shouldn't be one

Hi friends,

I'm getting the inspection "Binary operation argument type MongoError is not compatible with type string" on the line "if (field === 'ccNumber') highlightCard();"

This started showing up after I added mongodb to the project's package.json. Other than that though, Mongo isn't mentioned anywhere in the project. Plus, this line resides on a client side javascript file.

Invalidating cache doesn't help. Any ideas?

I'm running PhpStorm 2018.3.3 Build #PS-183.5153.36

Thanks!

2 comments

Looks as if PhpStom infers field type as MongoError for some reason. You can try specifying the type explicitly using JSdoc @type annotation, or limit the scope of <project_name>/node_modules library (https://www.jetbrains.com/help/webstorm/2018.3/configuring-javascript-libraries.html#ws_js_configuring_js_libs_change_scope) to the folder where your server-side code resides to avoid using the libraries from your package.json in client-side code

1

Thanks for the quick reply and helpful suggestions!

The JSdoc approach worked. Limiting scope wouldn't work though as both client and server code run off the same package.json.

However, oddly enough, this error is averted by replacing the looping mechanism that line was in from jQuery $.each(validators, function (field) {}) to native JS for (var field in validators) {}.

1

Please sign in to leave a comment.