Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript compile error #3677

Closed
1 of 2 tasks
windwalker opened this issue Nov 6, 2020 · 7 comments
Closed
1 of 2 tasks

typescript compile error #3677

windwalker opened this issue Nov 6, 2020 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@windwalker
Copy link

You want to:

  • report a bug
  • request a feature

Current behaviour

I have some troubles in compiling my code from typescript to javascript.
Compilation fails due to type error in namespace.d.ts and socket.d.ts。The Namespace and Socket class extends EventEmitter. However, they override 'emit' function and the signature is not compatible with the EventEmitter's emit function.

Is there any way to work around it?

Steps to reproduce (if the current behaviour is a bug)

Below is my tsconfig setting:

{
    "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./dist",
        "lib": ["es5", "es6"],
        "target": "es3",
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "allowSyntheticDefaultImports": true,
    },
    "include": ["./src/**/*"],
}

Here is the dependencies of the project:

"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"
  }

when I run: 'tsc', I got the following error:

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'.

Setup

  • OS: Windows
  • socket.io version: 3.0.0
@ntbraga
Copy link

ntbraga commented Nov 7, 2020

Having the same problem here!

@jameskentTX
Copy link

jameskentTX commented Nov 7, 2020

The same problem.
Debian, socket.io 3.0

@darrachequesne
Copy link
Member

Thanks, I could indeed reproduce the issue.

This should be fixed by 50671d9.

@darrachequesne darrachequesne added the bug Something isn't working label Nov 7, 2020
@LoveenDyall
Copy link

LoveenDyall commented Nov 8, 2020

Can you release this version ASAP?

Or let us target fix/typescript-emit branch directly!

@RPainter8West
Copy link

This seems worthy of a 3.0.1 release.

@darrachequesne
Copy link
Member

3.0.1 is out!

I've updated the TypeScript example here: https://github.com/socketio/socket.io/tree/master/examples/typescript

@darrachequesne darrachequesne added this to the 3.0.1 milestone Nov 9, 2020
@RPainter8West
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants