コードをtypescriptからjavascriptにコンパイルする際に問題が発生しました。
namespace.d.tsおよびsocket.d.tsのタイプエラーが原因でコンパイルが失敗します。NamespaceおよびSocketクラスはEventEmitterを拡張します。 ただし、これらは「emit」関数をオーバーライドし、署名はEventEmitterのemit関数と互換性がありません。
それを回避する方法はありますか?
以下は私の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
ブランチを直接ターゲットにしましょう!