Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/react/src/hooks/use-echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { echo } from "../config";
import type {
Channel,
ChannelData,
ChannelReturnType,
Connection,
ModelEvents,
ModelPayload,
Expand Down Expand Up @@ -157,7 +158,8 @@ export const useEcho = <
/**
* Channel instance
*/
channel: () => subscription.current,
channel: () =>
subscription.current as ChannelReturnType<TDriver, TVisibility>,
};
};

Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export type Channel = {
visibility: "private" | "public" | "presence";
};

export type ChannelReturnType<
T extends BroadcastDriver,
V extends Channel["visibility"],
> = V extends "presence"
? Broadcaster[T]["presence"]
: V extends "private"
? Broadcaster[T]["private"]
: Broadcaster[T]["public"];

export type ConfigDefaults<O extends BroadcastDriver> = Record<
O,
Broadcaster[O]["options"]
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/composables/useEcho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { echo } from "../config";
import type {
Channel,
ChannelData,
ChannelReturnType,
Connection,
ModelEvents,
ModelPayload,
Expand Down Expand Up @@ -173,7 +174,7 @@ export const useEcho = <
/**
* Channel instance
*/
channel: () => subscription,
channel: () => subscription as ChannelReturnType<TDriver, TVisibility>,
};
};

Expand Down
9 changes: 9 additions & 0 deletions packages/vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export type Channel = {
visibility: "private" | "public" | "presence";
};

export type ChannelReturnType<
T extends BroadcastDriver,
V extends Channel["visibility"],
> = V extends "presence"
? Broadcaster[T]["presence"]
: V extends "private"
? Broadcaster[T]["private"]
: Broadcaster[T]["public"];

export type ConfigDefaults<O extends BroadcastDriver> = Record<
O,
Broadcaster[O]["options"]
Expand Down