Saya memiliki beberapa masalah dalam menyusun kode saya dari skrip ketikan ke javascript.
Kompilasi gagal karena kesalahan jenis di namespace.d.ts dan socket.d.ts。Kelas Namespace dan Socket memperluas EventEmitter. Namun, mereka menimpa fungsi 'emit' dan tanda tangan tidak kompatibel dengan fungsi emit EventEmitter.
Apakah ada cara untuk mengatasinya?
Di bawah ini adalah pengaturan tsconfig saya:
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"lib": ["es5", "es6"],
"target": "es3",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
},
"include": ["./src/**/*"],
}
Berikut adalah dependensi proyek:
"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"
}
ketika saya menjalankan: 'tsc', saya mendapat kesalahan berikut:
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'.
Mengalami masalah yang sama di sini!
Masalah yang sama.
Debian, socket.io 3.0
Terima kasih, saya memang dapat mereproduksi masalah tersebut.
Ini harus diperbaiki oleh https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295.
Bisakah Anda merilis versi ini ASAP?
Atau izinkan kami menargetkan fix/typescript-emit
cabang secara langsung!
Ini tampaknya layak untuk rilis 3.0.1.
3.0.1 keluar!
Saya telah memperbarui contoh TypeScript di sini: https://github.com/socketio/socket.io/tree/master/examples/typescript
Terima kasih!
Komentar yang paling membantu
Bisakah Anda merilis versi ini ASAP?
Atau izinkan kami menargetkan
fix/typescript-emit
cabang secara langsung!