Skip to content

Commit

Permalink
fix(typings): accept string | undefined as init argument
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 24, 2023
1 parent 605de78 commit ba365d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/index.ts
Expand Up @@ -28,11 +28,7 @@ function lookup(
opts?: Partial<ManagerOptions & SocketOptions>
): Socket;
function lookup(
uri: string | Partial<ManagerOptions & SocketOptions>,
opts?: Partial<ManagerOptions & SocketOptions>
): Socket;
function lookup(
uri: string | Partial<ManagerOptions & SocketOptions>,
uri?: string | Partial<ManagerOptions & SocketOptions>,
opts?: Partial<ManagerOptions & SocketOptions>
): Socket {
if (typeof uri === "object") {
Expand Down
4 changes: 2 additions & 2 deletions test/support/util.ts
Expand Up @@ -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: () => void) => void) {
return new Promise<void>((resolve) => fn(resolve));
}

export function success(done, socket) {
Expand Down
13 changes: 12 additions & 1 deletion 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", () => {
Expand Down

0 comments on commit ba365d3

Please sign in to comment.