Improve generated TS schemas with `supabase gen types`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- postgresql, typescript
- Domain
- databases, developer-experience, tooling
Research direction
Start with the Supabase CLI's supabase gen types entry point and inspect how generated TypeScript represents database function returns, JSON fields, and domain types. Compare the current output with the requested inferred types and define a narrower, testable scope before implementing; done should include coverage for the selected cases.
Written by the indexing model from the issue text.
Description
I'm using supabase auth, supabase RLS, and the supabase postgREST api. I like the idea of pushing authorization and validation rules all into the db, rather than having them split across the app layer and db.
However, one of the biggest points of friction that I encounter when building this way is reflecting the schema of my supabase tables and functions in my NextJS typescript codebase.
I use the supabase gen types command built into the Supabase CLI, but I end up having to write a lot of additional overrides, because not everything I want is inferred. Here are some examples:
- DB function return types are always unknown - I end up having to write them myself and override the generated type
- JSON types are just generic JSON, even when a better type could be inferred, ex. { id: string, name: string } - should be able to infer these from function definitions or from JSONschema check constraints
- Does not autogenerate schema definitions for zod/yup/valibot, so I end up having to write these manually any time I have a form
- For custom enum types, the type generation works well, but for domain types (aka refinement types), the type is inferred as unknown. Even if the generator doesn't want to generate zod/yup/valibot schemas for these, it could at least generate the base type of the domain instead of unknown.
Given these limitations, I feel that it would've been faster to just use Supabase as a vanilla Postgres and use Prisma - this way, I could define schemas once in typescript and get autogenerated zod, sql, and ts types.
Addressing these limitations would make me significantly more productive using Supabase w/ RLS+auth+postgREST.
Are there any good community projects that offer improved typegen, or are there plans to improve the type generator in supabase cli?
right now, it feels like i either have to get off the "all supabase" stack, or write my own type generator if I want to stay productive
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 223
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from supabase/postgres-meta
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
supabase/postgres-meta#1147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
supabase/postgres-meta#1146 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1142 ·
All issues in supabase/postgres-meta
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·