我正试图将typescript添加到现有的电子应用程序。这是我的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
当我试图通过运行"tsc"来编译应用程序时命令,我得到很多以下错误:
node_modules/电子/electron.d。ts:8:20 -错误TS2304:找不到名称"事件"。8 . type GlobalEvent = Event &{returnValue: any};
node_modules/电子/electron.d。ts:5203:59 -错误TS2304:找不到名称"MessagePort"。5203 postMessage(channel: string, message: any, transfer?): MessagePort[]): void;
…
如何解决这个问题?
解决方案是添加"dom"库到tsconfig。如这篇GitHub文章所示。这是我新的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}