Skip to content

Commit 5a3eafe

Browse files
fix(typings): accept string | undefined as init argument
Related: socketio/socket.io#4873
1 parent 605de78 commit 5a3eafe

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Diff for: lib/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ function lookup(
2828
opts?: Partial<ManagerOptions & SocketOptions>
2929
): Socket;
3030
function lookup(
31-
uri: string | Partial<ManagerOptions & SocketOptions>,
32-
opts?: Partial<ManagerOptions & SocketOptions>
33-
): Socket;
34-
function lookup(
35-
uri: string | Partial<ManagerOptions & SocketOptions>,
31+
uri?: string | Partial<ManagerOptions & SocketOptions>,
3632
opts?: Partial<ManagerOptions & SocketOptions>
3733
): Socket {
3834
if (typeof uri === "object") {

Diff for: test/support/util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* @see https://webdriver.io/docs/frameworks/#using-mocha
1111
* @param fn
1212
*/
13-
export function wrap(fn) {
14-
return new Promise((resolve) => fn(resolve));
13+
export function wrap(fn: (done: (err?: Error) => void) => void) {
14+
return new Promise<Error>((resolve) => fn(resolve));
1515
}
1616

1717
export function success(done, socket) {

Diff for: test/typed-events.test-d.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { io, Socket } from "..";
22
import type { DefaultEventsMap } from "@socket.io/component-emitter";
33
import { expectError, expectType } from "tsd";
4-
import { createServer } from "http";
54

65
// This file is run by tsd, not mocha.
76

7+
describe("init", () => {
8+
io();
9+
io("https://example.com");
10+
io({
11+
forceNew: true,
12+
});
13+
io("https://example.com", {
14+
forceNew: true,
15+
});
16+
io(process.env.NODE_ENV === "production" ? "https://example.com" : undefined);
17+
});
18+
819
describe("typed events", () => {
920
describe("no event map", () => {
1021
describe("on", () => {

0 commit comments

Comments
 (0)