From 5a3eafed1c4118ac3a06ec81a24491eec7d0655f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 24 Nov 2023 08:30:35 +0100 Subject: [PATCH] fix(typings): accept string | undefined as init argument Related: https://github.com/socketio/socket.io/issues/4873 --- lib/index.ts | 6 +----- test/support/util.ts | 4 ++-- test/typed-events.test-d.ts | 13 ++++++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 958cb623..938ca863 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -28,11 +28,7 @@ function lookup( opts?: Partial ): Socket; function lookup( - uri: string | Partial, - opts?: Partial -): Socket; -function lookup( - uri: string | Partial, + uri?: string | Partial, opts?: Partial ): Socket { if (typeof uri === "object") { diff --git a/test/support/util.ts b/test/support/util.ts index 40e39e10..0c514a83 100644 --- a/test/support/util.ts +++ b/test/support/util.ts @@ -10,8 +10,8 @@ * @see https://webdriver.io/docs/frameworks/#using-mocha * @param fn */ -export function wrap(fn) { - return new Promise((resolve) => fn(resolve)); +export function wrap(fn: (done: (err?: Error) => void) => void) { + return new Promise((resolve) => fn(resolve)); } export function success(done, socket) { diff --git a/test/typed-events.test-d.ts b/test/typed-events.test-d.ts index 89d59e37..1cb30d64 100644 --- a/test/typed-events.test-d.ts +++ b/test/typed-events.test-d.ts @@ -1,10 +1,21 @@ import { io, Socket } from ".."; import type { DefaultEventsMap } from "@socket.io/component-emitter"; import { expectError, expectType } from "tsd"; -import { createServer } from "http"; // This file is run by tsd, not mocha. +describe("init", () => { + io(); + io("https://example.com"); + io({ + forceNew: true, + }); + io("https://example.com", { + forceNew: true, + }); + io(process.env.NODE_ENV === "production" ? "https://example.com" : undefined); +}); + describe("typed events", () => { describe("no event map", () => { describe("on", () => {