8
access to enum unions in db.types.ts (CLI: supabase gen types typescript)
Source: supabase/supabase#27803 · opened by @logemann
Hi,
supabase gen types typescript generates PG enums as string literal unions which is how it should be. Problem is: There is no sane way of getting an array of those string literals. I need those values for my ZOD schemas to prevent double definitions which 100% will run out of sync.
My proposal: Create the string literal union types from a const context as so:
This way we could access the ENUM values from the generated schema types by just accessing the arrays which are the source for the string literal unions. I for myself need those to declare my ZOD schemas. Of course those attributes there map pretty much 1:1 to my database schema. I really dont want to double declare my enums. Should be enough to delcare them in Postgres DDL.
I could also try to make a pull request for this if somebody gives me a pointer where i can find the source code for the CLI command.
supabase gen types typescript generates PG enums as string literal unions which is how it should be. Problem is: There is no sane way of getting an array of those string literals. I need those values for my ZOD schemas to prevent double definitions which 100% will run out of sync.
My proposal: Create the string literal union types from a const context as so:
This way we could access the ENUM values from the generated schema types by just accessing the arrays which are the source for the string literal unions. I for myself need those to declare my ZOD schemas. Of course those attributes there map pretty much 1:1 to my database schema. I really dont want to double declare my enums. Should be enough to delcare them in Postgres DDL.
I could also try to make a pull request for this if somebody gives me a pointer where i can find the source code for the CLI command.
No pledges yet. Be the first to back this.
Comments
Similar requests
Generated TypeScript Types - Add type safe to Tables
2 votes · 0 comments
Add schema-aware Functions, Args, and Returns helper types to generated Supabase TypeScript types
1 vote · 0 comments
Better Typescript Types
43 votes · 0 comments
Improved type inference for JSONB columns with check constraints in supabase typescript client
3 votes · 0 comments
Extension to the current "Copy as Markdown" function
1 vote · 0 comments
No comments yet.