Repository navigation
Allow custom connector classes in the React, Vue, and Svelte wrappers - #554
Merged
taylorotwell merged 2 commits intoSep 18, 2026
Merged
Conversation
The React, Vue, and Svelte wrappers constrained configureEcho() and echo() to BroadcastDriver, which excludes the "function" arm of Broadcaster, so passing a custom connector class failed with TS2322 even though laravel-echo and the wrapper runtime both support it. Widen the wrapper generics to keyof Broadcaster and skip the driver defaults lookup when the broadcaster is a connector class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The React, Vue, and Svelte wrappers reject custom connector classes at the type level, even though
laravel-echoand the wrappers' own runtime support them.laravel-echoexposes the custom-connector arm throughBroadcaster["function"], whosebroadcasteris aConstructor<…>, andEcho's own generic isT extends keyof Broadcaster. The wrappers, however, constrainconfigureEcho()/echo()toBroadcastDriver, which isExclude<keyof Broadcaster, "function">:So this fails to compile:
Runtime was never the problem:
defaults[WaveConnector]isundefined, so the spread is a no-op, andnew Echo(config)already accepts a connector class (Echo#connect()has anisConstructor(this.options.broadcaster)branch). Only the wrappers' generic is narrower than the library it wraps, so users have to cast or uselaravel-echodirectly and give up the framework helpers.Change
In
packages/{react,vue,svelte}/src/config/index.ts:configureEcho,echo, andgetEchoInstanceare constrained tokeyof Broadcasterinstead ofBroadcastDriver, matchingEcho<T extends keyof Broadcaster>.Echo's own constructor parameter,type EchoConfig = ConstructorParameters<typeof Echo<keyof Broadcaster>>[0], and built with an explicitnew Echo<keyof Broadcaster>(echoConfig). Without the explicit type argument, inference collapsesTback to the string drivers (viabroadcaster: T | Constructor) and rejects the"function"arm again.The
typeofnarrowing lands exactly onBroadcastDriver, so the lookup needs no cast.No runtime behavior changes for the built-in drivers: the same defaults are merged for every string broadcaster, and the previously-
undefinedlookup for a connector class is now simply skipped.Tests
Each wrapper gets a case in
tests/config.test.tsthat configures a custom connector class and asserts the instance is built from it and the passed options survive the merge. Because the test files are covered bytsc --noEmit, these also pin the type-level behavior — onmasterthey fail to compile with the exactTS2322above.Verified locally:
pnpm typecheck— clean across all four packages.pnpm -r run test— 111 / 63 / 49 / 34 tests pass.pnpm lint— no new errors.packages/vue; the emitted declaration is nowexport declare const configureEcho: <T extends keyof Broadcaster>(config: EchoOptions<T>) => void;.Docs
Each wrapper README gains a short note under
configureEchoshowing a custom connector class and stating that no defaults are merged in for it.Non-goals
useEcho,useChannel, and friends keepTDriver extends BroadcastDriver.Broadcaster["function"]'s channel types areany, so widening those generics would only let callers opt intoanychannels; it is unrelated to the reported error and left alone.