File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { echo } from "../config";
44import type {
55 Channel ,
66 ChannelData ,
7+ ChannelReturnType ,
78 Connection ,
89 ModelEvents ,
910 ModelPayload ,
@@ -157,7 +158,8 @@ export const useEcho = <
157158 /**
158159 * Channel instance
159160 */
160- channel : ( ) => subscription . current ,
161+ channel : ( ) =>
162+ subscription . current as ChannelReturnType < TDriver , TVisibility > ,
161163 } ;
162164} ;
163165
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ export type Channel = {
1616 visibility : "private" | "public" | "presence" ;
1717} ;
1818
19+ export type ChannelReturnType <
20+ T extends BroadcastDriver ,
21+ V extends Channel [ "visibility" ] ,
22+ > = V extends "presence"
23+ ? Broadcaster [ T ] [ "presence" ]
24+ : V extends "private"
25+ ? Broadcaster [ T ] [ "private" ]
26+ : Broadcaster [ T ] [ "public" ] ;
27+
1928export type ConfigDefaults < O extends BroadcastDriver > = Record <
2029 O ,
2130 Broadcaster [ O ] [ "options" ]
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { echo } from "../config";
44import type {
55 Channel ,
66 ChannelData ,
7+ ChannelReturnType ,
78 Connection ,
89 ModelEvents ,
910 ModelPayload ,
@@ -173,7 +174,7 @@ export const useEcho = <
173174 /**
174175 * Channel instance
175176 */
176- channel : ( ) => subscription ,
177+ channel : ( ) => subscription as ChannelReturnType < TDriver , TVisibility > ,
177178 } ;
178179} ;
179180
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ export type Channel = {
1616 visibility : "private" | "public" | "presence" ;
1717} ;
1818
19+ export type ChannelReturnType <
20+ T extends BroadcastDriver ,
21+ V extends Channel [ "visibility" ] ,
22+ > = V extends "presence"
23+ ? Broadcaster [ T ] [ "presence" ]
24+ : V extends "private"
25+ ? Broadcaster [ T ] [ "private" ]
26+ : Broadcaster [ T ] [ "public" ] ;
27+
1928export type ConfigDefaults < O extends BroadcastDriver > = Record <
2029 O ,
2130 Broadcaster [ O ] [ "options" ]
You can’t perform that action at this time.
0 commit comments