Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Conversation

kakeluh
Copy link

@kakeluh kakeluh commented Apr 3, 2025

What kind of change does this PR introduce?

infer payload type sent by realtime.broadcast_changes

What is the current behavior?

  on<{ record: Tables<"todos"> }>("broadcast", { event: "INSERT" }, ({ payload: { record } }) => {})

What is the new behavior?

  on<Tables<"todos">>("broadcast", { event: "INSERT" }, ({ payload: { record } }) => {})

Additional context

@grdsdev grdsdev requested a review from Copilot June 2, 2025 12:22
Copy link

@Copilot Copilot AI left a 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*Payload types with a shared base and specific insert/update/delete variants.
  • Adds overloaded on<T> methods for BROADCAST events (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 event field 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 },

Comment on lines +34 to +39
type RealtimeBroadcastChangesPayloadBase = {
id: string
schema: string
table: string
}

Copy link

Copilot AI Jun 2, 2025

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.

Suggested change
type RealtimeBroadcastChangesPayloadBase = {
id: string
schema: string
table: string
}
type RealtimeChangesPayloadBase = {
schema: string
table: string
}
type RealtimeBroadcastChangesPayloadBase = RealtimeChangesPayloadBase & {
id: string
}

Copilot uses AI. Check for mistakes.

payload: T
}) => void
): RealtimeChannel
on<T extends { [key: string]: any }>(
Copy link

Copilot AI Jun 2, 2025

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.

Suggested change
on<T extends { [key: string]: any }>(
on<T extends Record<string, unknown>>(

Copilot uses AI. Check for mistakes.

payload: T
}) => void
): RealtimeChannel
on<T extends { [key: string]: any }>(
Copy link

Copilot AI Jun 2, 2025

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.

Copilot uses AI. Check for mistakes.

@mandarini
Copy link
Contributor

Moved to supabase/supabase-js#1747

@mandarini mandarini closed this Oct 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants