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

Can't emit namespace events without arguments in TS #4917

Closed
BerkieBb opened this issue Jan 6, 2024 · 3 comments
Closed

Can't emit namespace events without arguments in TS #4917

BerkieBb opened this issue Jan 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@BerkieBb
Copy link

BerkieBb commented Jan 6, 2024

Describe the bug
After this change TypeScript doesn't recognize my events without arguments anymore and throws an error when I start my socket.
image

To Reproduce

Socket.IO server version: 4.7.3

Server

// This is not my actual code, but my code to reproduce my issue
import express from 'express';
import http from 'http';
import { Namespace, Server } from 'socket.io';
const app = express();
const server = http.createServer(app);
const io = new Server(server);

app.get('/', (_, res) => {
  res.send('<h1>Hello world</h1><script src="https://cdn.socket.io/4.7.3/socket.io.min.js"></script><script>var socket = io();  socket.on(\'test\', () => {console.log(\'test triggered\');});</script>');
});

declare namespace SocketServer {
  interface ClientEvents {
    ['test']: () => void;
    ['with-args']: (arg: string) => void;
    ['with-args-two']: (arg: string) => void;
  }
}

const namespace: Namespace<SocketServer.ClientEvents> = io.of('/server');

namespace.on('connection', () => {
  console.log('a user connected');
  namespace.emit('test');
});

server.listen(3000, () => {
  console.log('listening on *:3000');
});

Client

Don't have one for my reproduction code and already in the HTML sent when the app is connected.

Expected behavior
For the event to get recognized by TypeScript even though no arguments were provided and for it to compile without any issues.

Platform:

  • Device: Desktop
  • OS: Windows 10
@BerkieBb BerkieBb added the to triage Waiting to be triaged by a member of the team label Jan 6, 2024
@BerkieBb BerkieBb changed the title Can't emit events without arguments in TS Can't emit namespace events without arguments in TS Jan 6, 2024
@lts20050703
Copy link

Related to #4914

@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Jan 8, 2024
@darrachequesne
Copy link
Member

This should be fixed by cb6d2e0, included in version 4.7.4.

Could you please check?

@BerkieBb
Copy link
Author

Seems to be fixed, 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

3 participants