Importing Electron classes with Typescript

早过忘川 提交于 2019-12-13 13:53:16

问题


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:


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
  });
});


来源:https://stackoverflow.com/questions/31302253/importing-electron-classes-with-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!