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


Comment actions Permalink

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 ( to the folder where your server-side code resides to avoid using the libraries from your package.json in client-side code

Comment actions Permalink

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) {}.


Please sign in to leave a comment.