javascript - TypeError:无法读取 TypeScript 生成的 JavaScript 文件上未定义的属性“推送”
问题描述
TypeError: Cannot read property 'push' of undefined
当我运行我的应用程序时,我得到了。我正在用 TypeScript 编写并编译为ES5。
打字稿文件
// Holds all windows
private windows!: [string,BrowserWindow][];
/**
* Creates a browser window and returns it.
* Note: The window will auto .show() when returned
*
* @param windowView View name to be loaded
* @param windowOptions BrowserWindow options
*/
public createWindow(windowView:string, windowOptions?:BrowserWindowConstructorOptions): BrowserWindow {
// Instantiates the BrowserWindow
let window = new BrowserWindow(windowOptions)
// Loads the view into the BrowserWindow
window.loadFile(this.VIEWS_PATH + '/' + windowView + this.VIEWS_EXTENSION)
// Adds view and window to BrowserWindow tupple array for futher use
this.windows.push([windowView, window])
// Closes and deletes this specific BrowserWindow from the BrowserWindow tupple array
window.on('close', (event) => {
console.log('deleted', event.sender.id)
this.deleteWindow(undefined, event.sender.id)
})
return window
}
TypeScript 生成的 JavaScript 文件
/**
* Creates a browser window and returns it.
* Note: The window will auto .show() when returned
*
* @param windowView View name to be loaded
* @param windowOptions BrowserWindow options
*/
createWindow(windowView, windowOptions) {
// Instantiates the BrowserWindow
let window = new electron_1.BrowserWindow(windowOptions);
// Loads the view into the BrowserWindow
window.loadFile(this.VIEWS_PATH + '/' + windowView + this.VIEWS_EXTENSION);
// Adds view and window to BrowserWindow tupple array for futher use
this.windows.push([windowView, window]);
// Closes and deletes this specific BrowserWindow from the BrowserWindow tupple array
window.on('close', (event) => {
console.log('deleted', event.sender.id);
this.deleteWindow(undefined, event.sender.id);
});
return window;
}
TypeScript 没有在 JavaScript 文件上定义 windows 元组数组,是因为它没有在 TypeScript 文件上初始化吗?任何解决方法?
非常感谢。
解决方案
试试private windows!: [string,BrowserWindow][]=[];
(:P)
推荐阅读
- c++ - 为什么字符串的 move() 会改变内存中的底层数据位置?
- python - 如何使用 pyinstaller 成功执行包含网页抓取代码的 python 脚本
- batch-file - 使用 ERRORLEVEL 检索 InstallUtil 的退出状态
- docker - Nginx 反向代理未使用主机名找到其他内部 Docker 容器
- python-3.x - 循环遍历列表和 t 测试时的 TypeError 操作数
- reactjs - Heroku:puppeteer chrome:加载共享库时出错:libX11-xcb.so.1
- javascript - Nodejs模型不采用图像类型?
- html - 平滑滚动锚链接没有发生 - 只是跳转到部分而不是滚动
- excel - Excel INDEX MATCH 列格式转换为行列格式
- azure - Azure 扬声器验证 API 的定价层错误