fix(typings): accept string | undefined as init argument

Related: https://github.com/socketio/socket.io/issues/4873
This commit is contained in:
Damien Arrachequesne
2023-11-24 08:30:35 +01:00
parent 605de78d2c
commit 5a3eafed1c
3 changed files with 15 additions and 8 deletions

View File

@@ -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") {

View File

@@ -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<Error>((resolve) => fn(resolve));
}
export function success(done, socket) {

View File

@@ -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", () => {