supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

fix(realtime): add generic overload for postgres_changes event type

Open 7ttp opened this issue 2 months ago • 2 comments

Adds a generic overload for on() with postgres_changes that accepts any event type, enabling reusable subscription helpers with union types like '*' | 'INSERT' | 'UPDATE' | 'DELETE'.

Fixes "No overload matches this call" error when passing generic event parameters to channel.on('postgres_changes', ...).

closes https://github.com/supabase/supabase-js/issues/1451

7ttp avatar Dec 23 '25 22:12 7ttp

Coverage Status

coverage: 95.349% (+14.0%) from 81.389% when pulling eaf16eff728faf2708c048e3404f22f0c9368e17 on 7ttp:fix/realtime11 into 30f96004cf1c9f18abd55c21bcecb2f360effc72 on supabase:master.

coveralls avatar Dec 23 '25 22:12 coveralls

@7ttp thank you for this PR. Can you please add a test for the new functionality? It can go in packages/core/realtime-js/test/RealtimeChannel.postgres.test.ts. Something like:

...
      const event: '*' | 'INSERT' | 'UPDATE' | 'DELETE' = 'INSERT'
      // This should compile without errors (previously required `as any`)
      channel.on(
        'postgres_changes',
        {
          event,
          schema: 'public',
          table: 'users',
        },
...
      )
...
      expect(channel.bindings.postgres_changes.length).toBe(1)
...

mandarini avatar Jan 05 '26 14:01 mandarini

@mandarini could u please have a look at this now! and let me know if anything else is required 😁💚

7ttp avatar Jan 22 '26 09:01 7ttp

@7ttp can you please rebase your PR with latest master? We made some updates in the workflows, and it will be blocked if you don't rebase

mandarini avatar Jan 22 '26 12:01 mandarini