Supabase encounters various errors during operation

I am encountering some issues while using supabase with TypeScript. Interestingly, I can see the errors in WebStorm, but not in VSCode. Can you provide any assistance?

supabase
      .channel('custom-all-channel')
      .on(
        'postgres_changes',
        { event: '*', schema: 'public', table: 'players_online' },
        (payload) => {
          if (payload.eventType === 'INSERT') {
            players = [...players, { name: payload.new.name, id: payload.new.id }]
          }
          if (payload.eventType === 'DELETE') {
            players = players.filter((pl) => pl.id !== payload.old.id)
          }
        }
      )
      .subscribe()

I am facing 2 errors:

  1. Argument type "postgres_changes" is not assignable to parameter type
    ${REALTIME_LISTEN_TYPES.BROADCAST}
  2. Argument type {schema: string, event: string, table: string} is not assignable to parameter type {event: string}

I am unsure of what I might be missing, can you provide any insights?

Answer №1

Dealing with a similar problem, I found a rather peculiar solution. I simply copied and pasted this specific code snippet, then tweaked it to fit my requirements.

const updates = client
  .channel('database-updates')
  .on(
    'mysql_updates',
    {
      event: '*',
      schema: 'public',
      table: 'tasks',
    },
    (data) => console.log(data)
  )
  .subscribe()

Answer №2

When using Typescript, it attempts to find a match between the function payload and one of the states: "broadcast", "postgres_changes", or "presence". Make sure to define the type for the payload with one of the options below:

  1. RealtimePostgresChangesPayload<Tables<"todos">>
    is the recommended approach.
  2. RealtimePostgresChangesPayload<Record<string, any>>
  3. any
supabase
  .channel("TABLE-DB-CHANGES")
  .on("postgres_changes",
    {
       event: '*',
       schema: 'public',
       table: 'todos',
     }, (payload: RealtimePostgresChangesPayload<Tables<"todos">>)=>onTableChange(payload)). 
     .subscribe();

Alternatively, you can use 'any' to bypass this requirement...

supabase
  .channel("TABLE-DB-CHANGES")
  .on("postgres_changes",
    {
       event: '*',
       schema: 'public',
       table: 'todos',
     }, (payload: any)=>onTableChange(payload)). 
     .subscribe();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Explore a vast array of items in a collection

I have a massive collection of various objects that I need to sift through. With over 60,000 elements, the search operation can sometimes be painfully slow. One typical object in this array has the following structure: { "title": "title" "company": ...

Encountering issues when trying to combine Sequelize with TypeScript

As I attempted to transition my NodeJs application to TypeScript, I encountered issues with Sequelize. Upon attempting to implement the code from a website, an error occurred: This expression is not constructable. Type 'typeof import("/home/de ...

Tips for including multiple directives in a component

Apologies in advance for my lack of clarity in expressing this question, which is why I am seeking assistance rather than finding the solution on my own. My query pertains to loading a component within another one and specifying it in the directive. Below ...

Has the GridToolbarExport functionality in Material UI stopped working since the latest version update to 5.0.0-alpha.37?

I have created a custom toolbar for my Data Grid with the following layout: return ( <GridToolbarContainer> <GridToolbarColumnsButton /> <GridToolbarFilterButton /> <GridToolbarDensitySelector /> <Gr ...

Combining Layouts and Providers: A Guide to Using Both on a Single Page

I am facing an issue with my provider that is responsible for refreshing a token by making a request to the server. Additionally, I have a basic layout featuring a sidebar that I want to use only on a specific route. However, I am unsure about where to add ...

Exploring NestJs: The Importance of DTOs and Entities

In my project, I'm currently experimenting with utilizing DTOs and Entities in a clever manner. However, I find it more challenging than expected as I develop a backend system for inventory management using NestJs and TypeOrm. When my client sends me ...

Form validation errors were detected

Currently, I am working with a formgroup that contains input fields with validations set up in the following manner: <mat-form-field class="mat-width-98" appearance="outline"> <mat-label>Profession Oc ...

Tips for styling the Button component in the shadcn/ui library for maximum impact

I'm currently working on a project using the shadcn/ui library. How can I properly customize it to meet my specific needs? For example, let's say I require an extra large red rounded Button for a call-to-action button in my project. What would be ...

Retrieve all elements within an Angular6 Directive that share the same name as the Directive

I have created a custom Directive called isSelected and applied it to several elements in different components as shown below: <i isSelected class="icon"></i> <i isSelected class="icon"></i> <i isSelected class="icon"></i ...

Verify if a particular string is present within an array

I am in possession of the key StudentMembers[1].active, and now I must verify if this particular key exists within the following array const array= ["StudentMembers.Active", "StudentMembers.InActive"] What is the method to eliminate the index [1] from Stu ...

Jest is throwing an error: Unable to access property from undefined while trying to import from a custom

I developed a package called @package/test. It functions perfectly when imported into a new, empty React TypeScript application. However, issues arise within Jest test suites. The usage of the CommonJS package version causes Jest to throw an error: Test ...

Can we utilize the elements in Array<keyof T> as keys in T?

Hello, I am trying to develop a function that accepts two parameters: an array of objects "T[]" and an array of fields of type T. However, I am encountering an issue when I reach the line where I invoke el[col] Argument of type 'T[keyof T]' i ...

Compiled TypeScript files are missing require statements for imported components

Recently delved into Angular 2 and encountered an unusual issue. I kicked off using the Angular 2 Quickstart repository on GitHub and incorporated some components with templates. For example: import { Component } from '@angular/core'; import { ...

Leveraging an AngularJS service within Angular framework

I am trying to incorporate an AngularJS service into my Angular project. Below is my main.ts file: import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {AppModule} from './app/app.module'; import {UpgradeMo ...

What is the most efficient way to dynamically load a script file before proceeding with the rest of the code execution?

In my Angular home.component.ts file, I have added the script loading code as shown below: export class HomeComponent { constructor() { this.loadDynamicScript(); } public loadDynamicScript() { var script = document.createElement(&a ...

What is the reason for my algorithm's inability to work with this specific number?

I'm currently working on creating an algorithm to compute the sum of prime numbers that are less than or equal to a specified number. Below is my attempt: function calculatePrimeSum(num) { // initialize an array with numbers up to the given num let ...

Differences in weekend start and end days vary across cultures

Looking for a solution to determine the weekend days per culture code in Typescript/Javascript? While most countries have weekends on Sat-Sun, there are exceptions like Mexico (only Sunday) and some middle-eastern countries (Fri-Sat). It would be helpful ...

Pause before sending each request

How can we optimize the Async Validator so that it only sends a request to JSON once, instead of every time a letter is typed in the Email form? isEmailExist(): AsyncValidatorFn { return (control: AbstractControl): Observable<any> => { ...

Troubleshooting `TypeError: document.createRange is not a function` error when testing material ui popper using react-testing-library

I am currently working with a material-ui TextField that triggers the opening of a Popper when focused. My challenge now is to test this particular interaction using react-testing-library. Component: import ClickAwayListener from '@material-ui/core/ ...

Is it Possible for the Number Array Type to Not Be Recognized as an Array?

export class ... { single: any[] = []; multi: any[] = []; view: number[] = [700, 400]; ... <Removed for brevity> } Error Message: It says 'Type 'number[]' is not assignable to t ...