Search code examples
typeselectronwebstormlibraries

How to setup Electron typing/completion in WebStorm 2020.2+?


Is anyone aware of a more up-to-date guide than this old JetBrains blog? Specifically, I’m trying to configure the code completion and types in WebStorm 2020.2, and the instructions in the "Configuring code completion" section don’t seem to work anymore. I can’t find any newer solution/guide online that doesn't reference that old article, and primarily just want WebStorm to properly recognize the Electron types/functions/etc.

WebStorm Settings

Path for electron.d.ts file is ~/node_modules/electron/electron.d.ts, and its contents look correct from what I can tell.

I've tried changing the Library Type to Debug and Release, neither works - as well as changing the Framework type from Custom to every other option, with no luck. I also tried another method I found that directly installs @types/electron, but that's deprecated and doesn't have the proper contents, so I immediately uninstalled that.

Alternate Route Attempt

Thanks in advance!


Solution

  • The completion should work out of the box, as type definitions come bundled with recent electron versions (see node_modules/electron/electron.d.ts), adding a library is only required if electron is installed globally. So I'd recommend removing both the library and a conflicting @types/electron package.

    As far as I can see from screenshot, you have problems with other libraries as well (for example, require() call and process are not resolved though Node.js coding assistance is enabled). Can be a problem with third-party plugins or file types assignments (for example, if *.ts and/or *.d.ts patterns are assigned to a file type other than Typescript, the IDE won’t be able to use typings for types resolving)