npm install electron to get up-to-date Electron typings in your project.
TypeScript solves this problem with definition files. A TypeScript definition file describes all the functions of a library and its expected input and output types. When library authors bundle a TypeScript definition file with their published library, consumers of that library can explore its API right inside their editor and start using it right away, often without needing to consult the library's documentation.
Many popular projects like Angular, Vue.js, node-github (and now Electron!) compile their own definition file and bundle it with their published npm package. For projects that don't bundle their own definition file, there is DefinitelyTyped, a third-party ecosystem of community-maintained definition files.
Starting at version 1.6.10, every release of Electron includes its own TypeScript definition file. When you install the
electron package from npm, the
electron.d.ts file is bundled automatically with the installed package.
The safest way to install Electron is using an exact version number:
npm install electron --save-dev --save-exact
Or if you're using yarn:
yarn add electron --dev --exact
If you were already using third-party definitions like
@types/node, you should remove them from your Electron project to prevent any collisions.
The definition file is derived from our structured API documentation, so it will always be consistent with Electron's API documentation. Just install
electron and you'll always get TypeScript definitions that are up to date with the version of Electron you're using.
For a summary of how to install and use Electron's new TypeScript annotations, watch this short demo screencast:
Once your editor is configured for TypeScript, you'll start to see more context-aware behavior like autocomplete suggestions, inline method reference, argument checking, and more.
Getting started with TypeScript
If you're new to TypeScript and want to learn more, this introductory video from Microsoft provides a nice overview of why the language was created, how it works, how to use it, and where it's headed.
This project would not have been possible without the help of Electron's community of open-source maintainers. Thanks to Samuel Attard, Felix Rieseberg, Birunthan Mohanathas, Milan Burda, Brendan Forster, and many others for their bug fixes, documentation improvements, and technical guidance.
If you encounter any issues using Electron's new TypeScript definition files, please file an issue on the electron-typescript-definitions repository.