supabase/postgres-meta

Generating types for a postgresql array results in Typescript unknown property

tom-at-pixel opened this issue · 4 comments

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

Generating TypeScript types for a Supabase project is resulting in unexpected unknown properties. Specifically, any array type (e.g. text[]) generates unknown (instead of e.g. string[]).

To Reproduce

  1. Define any type with text[] in Supabase:
CREATE TYPE example_type AS (
  my_text_array text[]
);
  1. Generate types in client project:
npx supabase gen types typescript --schema public

Observe the unknown property in the generated TypeScript types:

example_type: {
  my_text_array: unknown
}

Expected behavior

I would expect a string[] property in the generated types:

example_type: {
  my_text_array: string[]
}

System information

  • OS: MAC OS
  • Version of supabase CLI: 1.60.2
gregnr commented

Thanks for reporting this @tom-at-pixel. I'm going to transfer this to the postgres-meta repo and someone there can give you a hand.

@tom-at-pixel @gregnr is this issue fixed already? i dont seem to be able to reproduce.

@mahendraHegde Sorry for the delay in response. This is still an issue.

To repro, open a query editor in Supabase Studio and run this code:

CREATE TYPE test_array_type AS (
  my_text_array text[]
);

Then generate the types on the client-side:

npx supabase gen types typescript --schema public

The generated types include:

export interface Database {
  public: {
    ...
    CompositeTypes: {
      ...
      test_array_type: {
        my_text_array: unknown
      }
    }
  }
}

I would expect my_text_array to be of type string[], but maybe I am misunderstanding something and this is the expected behavior.