Socket.io: 打字稿编译错误

创建于 2020-11-06  ·  7评论  ·  资料来源: socketio/socket.io

你想要:

  • [x]报告错误
  • []请求功能

当前行为

将我的代码从打字稿编译为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'.

设定

  • 操作系统:Windows
  • socket.io版本:3.0.0

最有用的评论

您可以尽快发布此版本吗?

或者让我们直接定位fix/typescript-emit分支!

所有7条评论

这里有同样的问题!

同样的问题。
Debian,socket.io 3.0

谢谢,我确实可以重现该问题。

这应该通过https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295进行修复

您可以尽快发布此版本吗?

或者让我们直接定位fix/typescript-emit分支!

这似乎值得3.0.1发布。

3.0.1出来了!

我在这里更新了TypeScript示例: https :

谢谢!

此页面是否有帮助?
0 / 5 - 0 等级