-
Notifications
You must be signed in to change notification settings - Fork 227
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
Ability to Generate Typescript Type Definitions from Server Schema #327
Comments
This would be super nice to have in the Supabase CLI, which incidentally appears to be on the roadmap already. Would be great to also have the |
Although not perfect, cli v1 does support type generation for tables. https://supabase.com/docs/reference/cli/usage#supabase-gen If you encounter any issues with type gen, please don’t hesitate to open another issue. We will look into it asap. |
@sweatybridge does this only work if self-hosting Supabase? |
Hi @RyanTippsTX , the CLI supports typegen for Supabase hosted project. supabase gen types typescript --db-url <your_project_url> You can obtain the url from your project dashboard -> database tab. |
can i do this without a toml file & linking? |
Currently you can do this without linking but |
Thank you |
I don't understand how to generate the typescript types by reading the documentation. I've come so far by watching your new Supabase Launch Week videos. But they also skip the part on how to do it with |
@bennik88 try using Overall, for @bennik88 or for anyone else, i was able to generate types doing the following: from your terminal: Then download docker if you don't already have it (easiest way is directly from their site, or you can use brew), and then let it run. You dont need to do anything else in docker or be familiar with docker. back in terminal: And finally Then in your javascript files, you can do something like this:
After you generate the types, you can delete the supabase directory & the toml file, or add the directory to your gitignore, or just add it to your version control. If you delete it, you will have to re-init when you want to generate types in the future when you inevitably modify your db schema. |
Just an update: you can now generate types without init/linking/etc. - all you need to do is to login with your access token: supabase login
supabase projects list
supabase gen types typescript --project-id abcdefghijkl |
This works, but why this is not mentioned in the docs? I tried openapi-typescript which did not work. |
@abhay187 You can use Output Redirection in your shell command, for example:
|
We're working on an updated docs for TypeScript support. openapi-typescript isn't compatible with supabase-js v2. |
Hey, I'm using |
I also got the same error then I upgraded to
Please note that the autocomplete might not show |
@abhagsain Thanks, that was it! |
Should add this to docs |
I ran
|
Looks like you're forgetting |
|
thanks. this works. Additionally, i got
|
Same as supabase/realtime-js#153
Feature request
As a client, I would like to generate typescript definitions for my supabase realtime client -- call it the Typed-SDK -- based on the current schema in my postgres database.
I would also like to have the option to be notified when the types I am trying to use are "out of date" with the database's current schema types.
Describe the solution you'd like
Additional context
The text was updated successfully, but these errors were encountered: