Demo project: https://github.com/Dragory/webstorm-type-problem-demo
Using WebStorm 2020.2 with Node.js 14.7.0 (but also confirmed issue appears when using Node.js 12) on Windows 10. Tested with project inside WSL2 and outside.
In the demo linked above, WebStorm is unable to resolve types (hinted with JSDoc) from the "discord.js" module for auto-completion in certain situations when using require() in a .js file. The module supplies its own typings and they work correctly in e.g. TypeScript projects and VS Code. Since the module's types rely on @types/node, those are installed as well.
Below are screenshots of the two examples in the demo (from index.js, project linked above) where types don't work properly for auto-completion (see full demo project for more context). Both examples work in VS Code.
1. Entirely unknown type, or guessed as "Object":
2. Auto-completion provides suggestions from global "Client" type (in this case, from lib.webworker.d.ts):
The demo also contains three examples where I was able to get WebStorm to resolve the types properly, but each approach came with its own issues. More details in the demo project.
Does anyone know why this might be happening? Is it a bug in WebStorm, or something where WebStorm and VS Code disagree on the correct course of action? Or perhaps I should be hinting the types in .js files in a different way entirely?