Supabase 类型错误

问题描述 投票:0回答:1

我正在使用带有 typescript 的 supabase 并遇到一些错误。我在 webstorm 中看到它们,但在 vscode 中没有。你能帮我吗?

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()

我收到 2 个错误:

  1. 参数类型“postgres_changes”不可分配给参数类型
    ${REALTIME_LISTEN_TYPES.BROADCAST}
  2. 参数类型 {schema: string, event: string, table: string} 不可分配给参数类型 {event: string}

我错过了什么?

typescript supabase
1个回答
0
投票

我也有同样的问题。这是一种奇怪的解决方案,但我所做的只是复制并粘贴这个确切的片段,并根据我的需要进行编辑。

const changes = client
  .channel('table-db-changes')
  .on(
    'postgres_changes',
    {
      event: '*',
      schema: 'public',
      table: 'todos',
    },
    (payload) => console.log(payload)
  )
  .subscribe()
© www.soinside.com 2019 - 2024. All rights reserved.