Import .BrowserWindow electron into TypeScript

I am trying to get electron (0.37) and typescript (1.8), with Types working properly. I'm having trouble importing BrowserWindow. In older examples, this seems like a separate require('browser-window') , but in the current version its electron.BrowserWindow .

Following an example, I found that my typescript:

 import electron = require('electron'); const BrowserWindow = electron.BrowserWindow; ... var mainWindow:BrowserWindow = new BrowserWindow({width: main_width, height: main_height}); 

Unfortunately, WebStorm and its typescript compiler complain: "TS2304: cannot find the name BrowserWindow"; especially in the description of the variable. if I remove the type declaration from the variable, it works.

 var mainWindow = new BrowserWindow({width: main_width, height: main_height}); 

... but that seems to defeat the purpose of typescript, though?

I tried several different ways around this, but I can't get it to work fine. For example, if I do: import BrowserWindow = Electron.BrowserWindow compiler is happy, but javascript fails because Electron (typescript namespace) is not defined.

Admittedly, I'm new to typescript.

+5
source share
1 answer

var mainWindow: BrowserWindow

You probably want:

 var mainWindow:Electron.BrowserWindow 
+9
source

All Articles