【发布时间】:2017-04-04 11:51:32
【问题描述】:
我正在尝试为可以在电子应用程序中提供类型安全性的事件指定一些覆盖。
对于我的类型:
export type SectionName = 'webview'
| 'index'
| 'settings'
export interface ShowSection {
key: SectionName,
}
我想扩充这段代码:
import {
ipcMain,
} from 'electron'
ipcMain.on('rendered', (event) => {
const sender = event.sender
event.sender.send('show-section', {
key: 'index',
})
})
发件人的类型为Electron.WebContents,定义为here
我尝试过这样的扩充:
declare namespace Electron {
interface WebContents extends NodeJS.EventEmitter {
send(channel: 'show-section', arg: ShowSection): void;
}
}
我不知道如何做到这一点,以便我可以在个别事件上获得类型安全。
谢谢
【问题讨论】:
标签: typescript typescript-typings