Skip to content

Server emitWithAck on typed Server has "never" typing #5257

@mrjogo

Description

@mrjogo

Describe the bug

emitWithAck doesn't seem to be picking up types correctly, so the type variable Ev is assigned never.

To Reproduce

Socket.IO server version: 4.8.1

Server

import { Server } from "socket.io";

interface ServerToClientEvents {
  someEvent: (callback: (err: Error) => void) => void;
}
interface ClientToServerEvents {}

const io = new Server<ClientToServerEvents, ServerToClientEvents>();
io.on("connection", async (socket) => {
  // Typescript gives error "Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)"
  await socket.emitWithAck("someEvent");

  // No error
  socket.emit("someEvent", (err) => {});
});

Client

No client code necessary.

Expected behavior
No Typescript error (similar to emit behavior)

Platform:

  • Device: Macbook Air M2
  • OS: MacOS Sonoma 14.6.1

Additional context
Seems to be the same bug as mentioned in the comment #4925 (comment), but different from that issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    to triageWaiting to be triaged by a member of the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions