将我的代码从打字稿编译为javascript时遇到了一些麻烦。
由于namespace.d.ts和socket.d.ts中的类型错误,编译失败。Namespace和Socket类扩展了EventEmitter。 但是,它们会覆盖“发射”功能,并且签名与EventEmitter的发射功能不兼容。
有什么办法可以解决它?
以下是我的tsconfig设置:
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"lib": ["es5", "es6"],
"target": "es3",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
},
"include": ["./src/**/*"],
}
这是项目的依赖项:
"dependencies": {
"debug": "^3.1.0",
"koa": "^2.13.0",
"socket.io": "^3.0.0"
},
"devDependencies": {
"@types/koa": "^2.11.6",
"@types/node": "^14.14.6",
"supervisor": "^0.12.0",
"typescript": "^4.0.5"
}
当我运行:“ tsc”时,出现以下错误:
node_modules/socket.io/dist/namespace.d.ts(89,5): error TS2416: Property 'emit' in type 'Namespace' is not assignable to the same property in base type 'EventEmitter'.
Type '(ev: string, ...args: any[]) => Namespace' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
Type 'Namespace' is not assignable to type 'boolean'.
node_modules/socket.io/dist/socket.d.ts(84,5): error TS2416: Property 'emit' in type 'Socket' is not assignable to the same property in base type 'EventEmitter'.
Type '(ev: string, ...args: any[]) => this' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
Type 'this' is not assignable to type 'boolean'.
Type 'Socket' is not assignable to type 'boolean'.
这里有同样的问题!
同样的问题。
Debian,socket.io 3.0
谢谢,我确实可以重现该问题。
这应该通过https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295进行修复
您可以尽快发布此版本吗?
或者让我们直接定位fix/typescript-emit
分支!
这似乎值得3.0.1发布。
谢谢!
最有用的评论
您可以尽快发布此版本吗?
或者让我们直接定位
fix/typescript-emit
分支!