-
-
Couldn't load subscription status.
- Fork 79
feat(realtime): enhance RealtimeChannel type #459
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Enhances the RealtimeChannel typing so that broadcast payloads infer the record shape directly from the generic parameter.
- Introduces
RealtimeBroadcast*Payloadtypes with a shared base and specific insert/update/delete variants. - Adds overloaded
on<T>methods forBROADCASTevents (ALL, INSERT, UPDATE, DELETE) returning strongly-typed payloads.
Comments suppressed due to low confidence (2)
src/RealtimeChannel.ts:441
- These new generic overloads and payload types should be covered by unit tests to ensure type inference works as expected and that events dispatch correct payload shapes.
on<T extends { [key: string]: any }>(
src/RealtimeChannel.ts:443
- For the ALL overload, the
eventfield is typed as ALL but at runtime the payload.event will be the specific INSERT/UPDATE/DELETE. Update the type to a union of specific events or rename to avoid misleading consumers.
filter: { event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL },
| type RealtimeBroadcastChangesPayloadBase = { | ||
| id: string | ||
| schema: string | ||
| table: string | ||
| } | ||
|
|
Copilot
AI
Jun 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] RealtimeBroadcastChangesPayloadBase overlaps with RealtimePostgresChangesPayloadBase (schema/table). Consider merging shared fields or extending one from the other to reduce duplication.
| type RealtimeBroadcastChangesPayloadBase = { | |
| id: string | |
| schema: string | |
| table: string | |
| } | |
| type RealtimeChangesPayloadBase = { | |
| schema: string | |
| table: string | |
| } | |
| type RealtimeBroadcastChangesPayloadBase = RealtimeChangesPayloadBase & { | |
| id: string | |
| } |
| payload: T | ||
| }) => void | ||
| ): RealtimeChannel | ||
| on<T extends { [key: string]: any }>( |
Copilot
AI
Jun 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using T extends { [key: string]: any } is very loose. Consider constraining to Record<string, unknown> or a more specific shape to improve type safety.
| on<T extends { [key: string]: any }>( | |
| on<T extends Record<string, unknown>>( |
| payload: T | ||
| }) => void | ||
| ): RealtimeChannel | ||
| on<T extends { [key: string]: any }>( |
Copilot
AI
Jun 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The multiple overloads for broadcast events are largely repetitive. You could consolidate them using a single overload with conditional types on filter.event to reduce duplication.
|
Moved to supabase/supabase-js#1747 |
What kind of change does this PR introduce?
infer payload type sent by
realtime.broadcast_changesWhat is the current behavior?
What is the new behavior?
Additional context