question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typescript compile error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
LoveenDyallcommented, Nov 8, 2020

Can you release this version ASAP?

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

2reactions
darrachequesnecommented, Nov 7, 2020

Thanks, I could indeed reproduce the issue.

This should be fixed by https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detect JavaScript errors during compile time using TypeScript ...
We all know that TypeScript is a language that compile itself to JavaScript. During compile-time TypeScript can emit errors to a terminal, ...
Read more >
TypeScript compile error due to typings - Stack Overflow
I'm using typescript 1.7.5, typings 0.6.9 and angular 2.0.0-beta.0. How can I get rid of the typescript compile error messages Duplicate ...
Read more >
Understanding TypeScript Errors for Beginners
Another common mistake amongst TypeScript beginners is to assume that because there are no compile-time errors there will be no run-time errors.
Read more >
Avoid TypeScript errors in your project by using the TypeScript ...
No more unexpected type errors! ... Avoid TypeScript errors in your project by using the TypeScript compiler.
Read more >
TypeScript tool window | WebStorm Documentation - JetBrains
Compile Errors  ... The tool window shows up only after you first compile your TypeScript code manually. This can be done in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found