Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import electron.BrowserWindow in TypeScript

I'm trying to get electron (0.37) and typescript (1.8), with Typings, working properly. I'm having trouble with the import of BrowserWindow. In older examples it seems to be a seperate require('browser-window'), but in the current version its electron.BrowserWindow.

following an example I found my TypeScript is:

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 is complaining: "TS2304: Cannot find name BrowserWindow"; specifically at the variable declaration. if I remove the type declaration from the variable, it works.

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

...but this seems to defeat the purpose of typescript though?

I've tried a few different ways around this, but cannot get it working properly. For instance, if I do: import BrowserWindow = Electron.BrowserWindow the compiler is happy, but the javascript fails because Electron (a typescript namespace) isn't defined.

Admittedly I'm new to typescript.

like image 719
Meirion Hughes Avatar asked May 10 '16 21:05

Meirion Hughes


1 Answers

var mainWindow:BrowserWindow

You probably want :

var mainWindow:Electron.BrowserWindow 
like image 189
basarat Avatar answered Oct 13 '22 20:10

basarat