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);