supabase / postgres-meta

A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries
https://supabase.com
Apache License 2.0
941 stars 126 forks source link

Generating types for a postgresql array results in Typescript unknown property #581

Closed tom-at-pixel closed 9 months ago

tom-at-pixel commented 1 year ago

Bug report

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

gregnr commented 1 year ago

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.

mahendraHegde commented 1 year ago

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

tom-at-pixel commented 1 year ago

@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.

Theiaz commented 9 months ago

I got the same problem, any updates?