Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
tom-at-pixel opened this issue May 24, 2023 · 4 comments · Fixed by #703
Closed
2 tasks done

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

tom-at-pixel opened this issue May 24, 2023 · 4 comments · Fixed by #703
Labels
bug Something isn't working

Comments

@tom-at-pixel
Copy link

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
@tom-at-pixel tom-at-pixel added the bug Something isn't working label May 24, 2023
@gregnr
Copy link
Member

gregnr commented May 25, 2023

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.

@gregnr gregnr transferred this issue from supabase/supabase May 25, 2023
@mahendraHegde
Copy link

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

@tom-at-pixel
Copy link
Author

tom-at-pixel commented Nov 15, 2023

@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
Copy link

Theiaz commented Mar 1, 2024

I got the same problem, any updates?

soedirgo pushed a commit to gulfaraz/postgres-meta that referenced this issue Mar 6, 2024
soedirgo added a commit that referenced this issue Mar 6, 2024
…e types (#703)

* fix: array types should not unknown fixes #581

* chore: update test random ids

* chore: keep pgType arg non-undefined

It should be the resposibility of the caller to make sure the argument
is defined

* chore: clarify type name

---------

Co-authored-by: Bobbie Soedirgo <bobbie@soedirgo.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants