socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.05k stars 10.11k forks source link

Incorrect Types for Client Initialisation #4873

Open piet-maier opened 11 months ago

piet-maier commented 11 months ago

Description

Initialising the socket.io client with an URL string or undefined depending on the environment (as in the Vue Example in the documentation) produces the following type error: "No overload matches this call."

It is possible to either pass a string or undefined in separate calls, but not a value that has the type string | undefined in one call.

Reproduction

Client Version: 4.7.2

import { io } from "socket.io-client";

const socket = io(import.meta.env.PROD ? undefined : "ws://localhost:3000/");

Expected Behaviour

There should not be a type error since the argument can be of either type, and the code works as expected.

darrachequesne commented 11 months ago

I could indeed reproduce the issue, I'm digging into this.