Skip to content

Type for emitWithAck seems incorrect #5367

@turnerhayes

Description

@turnerhayes

The Typsecript annotations for emitWithAck seem to be off. Following the docs, my types are as follows:

export interface ClientToServerEvents {
  "game:join": (args: {
    gameName: GameID;
    color: ColorID;
  }) => void;
  "game:connect": (args: {
    gameName: GameID;
  }) => void;
  "board:place-marble": (args: {
    gameName: GameID;
    position: BoardPosition;
    color: ColorID;
  }) => void;
}

When I call emitWithAck(), it shows an error:

const result = await this.socket.emitWithAck("game:join", {
            gameName,
            color,
        });
Expected 1 arguments, but got 2.

If I add an extra argument to the "game:join" callback type, the error disappears.

The type for emitWithAck is

emitWithAck<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: AllButLast<EventParams<EmitEvents, Ev>>): Promise<FirstArg<Last<EventParams<EmitEvents, Ev>>>>;

It seems like AllButLast should not be there; it should just take all parameters of the event handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions