File tree 4 files changed +23
-2
lines changed
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";
4
4
import type {
5
5
Channel ,
6
6
ChannelData ,
7
+ ChannelReturnType ,
7
8
Connection ,
8
9
ModelEvents ,
9
10
ModelPayload ,
@@ -157,7 +158,8 @@ export const useEcho = <
157
158
/**
158
159
* Channel instance
159
160
*/
160
- channel : ( ) => subscription . current ,
161
+ channel : ( ) =>
162
+ subscription . current as ChannelReturnType < TDriver , TVisibility > ,
161
163
} ;
162
164
} ;
163
165
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ export type Channel = {
16
16
visibility : "private" | "public" | "presence" ;
17
17
} ;
18
18
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
+
19
28
export type ConfigDefaults < O extends BroadcastDriver > = Record <
20
29
O ,
21
30
Broadcaster [ O ] [ "options" ]
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { echo } from "../config";
4
4
import type {
5
5
Channel ,
6
6
ChannelData ,
7
+ ChannelReturnType ,
7
8
Connection ,
8
9
ModelEvents ,
9
10
ModelPayload ,
@@ -173,7 +174,7 @@ export const useEcho = <
173
174
/**
174
175
* Channel instance
175
176
*/
176
- channel : ( ) => subscription ,
177
+ channel : ( ) => subscription as ChannelReturnType < TDriver , TVisibility > ,
177
178
} ;
178
179
} ;
179
180
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ export type Channel = {
16
16
visibility : "private" | "public" | "presence" ;
17
17
} ;
18
18
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
+
19
28
export type ConfigDefaults < O extends BroadcastDriver > = Record <
20
29
O ,
21
30
Broadcaster [ O ] [ "options" ]
You can’t perform that action at this time.
0 commit comments