【发布时间】:2019-06-09 05:15:51
【问题描述】:
我正在关注示例 here 并拥有以下 TypeScript 代码:
const { app, BrowserWindow, ipcMain } = require('electron');
let win;
function createWindow () {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadFile('bin/js-debug/index.html')
// Open the DevTools.
//win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
我将扩展名从 .js 更改为 .ts,但它开始显示错误。
我收到此警告:
变量“win”在某些无法确定其类型的位置隐式具有类型“any”。ts(7034)
所以我尝试像这样添加类型:
let win:BrowserWindow;
我收到这条消息:
'BrowserWindow' 指的是一个值,但在这里被用作一个类型。
注意:
如果我将类型设置为任何,错误就会消失。
let win:any;
【问题讨论】:
-
您所看到的并非严格意义上的错误,更多的是类型安全检查。如何导入浏览器窗口?
-
与
const { app, BrowserWindow, ipcMain } = require('electron');
标签: typescript electron