From d496ed45a17076e23da8784a627f5486a9f13117 Mon Sep 17 00:00:00 2001 From: Mark Russell <39885340+mark1russell7@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:35:57 -0500 Subject: [PATCH] fix(sio-client/types): fix the return type of emitWithAck() with the timeout() flag FirstArg only matches a callback with one argument. With the timeout() flag, the callback gets an error as first argument, so the type of the value was any instead of the type of the acknowledgement. This uses the same approach as FirstNonErrorArg in the socket.io package. The type test in test/typed-events.test-d.ts already expects this type, but the test:types script is "exit 0" since 8bead0f, so it does not run. --- packages/socket.io-client/lib/socket.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/socket.io-client/lib/socket.ts b/packages/socket.io-client/lib/socket.ts index 13c0ed97c..72030c363 100644 --- a/packages/socket.io-client/lib/socket.ts +++ b/packages/socket.io-client/lib/socket.ts @@ -50,6 +50,16 @@ export type AllButLast = T extends [...infer H, infer L] export type FirstArg = T extends (arg: infer Param) => infer Result ? Param : any; +export type FirstNonErrorTuple = T[0] extends Error + ? T[1] + : T[0]; +/** + * The type of the value of the acknowledgement: the first argument of the callback, or the second one when the + * timeout() flag adds an error as first argument. + */ +export type FirstNonErrorArg = T extends (...args: infer Params) => any + ? FirstNonErrorTuple + : any; export interface SocketOptions { /** @@ -514,7 +524,7 @@ export class Socket< public emitWithAck>( ev: Ev, ...args: AllButLast> - ): Promise>>> { + ): Promise>>> { return new Promise((resolve, reject) => { const fn = (arg1, arg2) => { return arg1 ? reject(arg1) : resolve(arg2);