Skip to content

Json type: Type instantiation is excessively deep and possibly infinite. #808

@michaelpumo

Description

@michaelpumo

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I have a Vue/Nuxt project with TypeScript which is throwing me an error with the profile table when I try to assign it to a variable based on the types generated from the DB. "Type instantiation is excessively deep and possibly infinite."

The problematic column in question is one called "links" which stores JSONB data. The type that is generated from the Supabase Cli using the command npx supabase gen types typescript creates a self referencing type called Json.

export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json | undefined }
  | Json[]

With my (generated) profile row types looking like:

profile: {
  Row: {
    about: string | null
    available: string | null
    avatar: string | null
    avatar_url: string | null
    created_at: string | null
    id: number
    links: Json | null // this is the problematic column.
    location: string | null
    name: string | null
    poster: string | null
    poster_url: string | null
    tagline: string | null
    updated_at: string
    user_id: string
    username: string | null
  }
}

In my Pinia Vue store I get the following error when trying to assign it against these types.

import type { Database } from '@/types/supabase'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    profile: null as Database['public']['Tables']['profile']['Row'] | null
  }),
  actions: {
    setProfile(profile: Database['public']['Tables']['profile']['Row'] | null) {
      this.profile = profile // Here is where the TS error occurs.
    }
  }
})

I'm guessing this error happens because the generated type is self referencing and TS does not know how deep it would be?

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a column and set its type to jsonb
  2. Generate types using the Supabase Cli
  3. Try to do something similar and see that TS complains.

Expected behavior

There should be no TS error.

Screenshots

Screenshot 2023-07-15 at 21 02 12 Screenshot 2023-07-15 at 21 16 15

System information

  • OS: Apple Macbook Pro M2 Ventura 13.4
  • Version of supabase-js: 2.26.0
  • Version of Node.js: 18.16.0

Additional context

I have not been able to see similar issues with other Supabase users but perhaps the use of JSONB is quite rare?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions