Skip to content

Conversation

@Willem-Jaap
Copy link
Contributor

@Willem-Jaap Willem-Jaap commented Nov 4, 2025

By explicitly intersecting the EchoOptions<T> type with { broadcaster: T }, we make the broadcaster field the source of truth for generic parameter T.

Previously, when only using EchoOptions<T> TypeScript couldn’t reliably infer T from the value of options.broadcaster.
This meant you either had to manually specify the type parameter (new Echo<"pusher">({...})) or you’d lose precise typing for the connector and channel methods.

// ✅ Type is automatically inferred from broadcaster
const echo1 = new Echo({
    broadcaster: "pusher",
    key: "my-key"
});
// Type: Echo<"pusher">
// echo1.connector is PusherConnector<"pusher">

const echo2 = new Echo({
    broadcaster: "socket.io"
});
// Type: Echo<"socket.io">
// echo2.connector is SocketIoConnector

// Channel methods are also correctly typed (this would previously be `any`):
const channel1 = echo1.channel("my-channel");
// Type: PusherChannel<"pusher">

const channel2 = echo2.channel("my-channel");
// Type: SocketIoChannel

@taylorotwell taylorotwell marked this pull request as draft November 4, 2025 14:34
@joetannenbaum joetannenbaum marked this pull request as ready for review November 4, 2025 16:39
@joetannenbaum
Copy link
Contributor

Good call, thank you!

@joetannenbaum joetannenbaum merged commit a9de68f into laravel:2.x Nov 4, 2025
5 checks passed
@Willem-Jaap Willem-Jaap deleted the willem-jaap/fix-broadcaster-inference branch November 5, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants