3
votes

How can I import Electron classes into a Typescript file, so that the intellisense is functioning?

For example, I'd like to turn this:

var BrowserWindow = require('browser-window');
var app = require('app');
app.on("ready", function() {
  var mainWindow = new BrowserWindow({
    width: 600,
    height: 800
  });
});

into something like this (doesn't work):

/// <reference path="./typings/github-electron/github-electron.d.ts"/>
var app = GitHubElectron.App;
app.on("ready", function() {
  var mainWindow = new GitHubElectron.BrowserWindow({
    width: 600,
    height: 800
  });
});
1

1 Answers

2
votes

Use type annotations on the return values of the require function calls:

var BrowserWindow: GithubElectron.BrowserWindow = require('browser-window');
var app = GitHubElectron.App = require('app');
app.on("ready", function() {
  var mainWindow = new BrowserWindow({
    width: 600,
    height: 800
  });
});