How to Generate Types for a Supabase Project
Learn how to generate types for a Supabase project using the Supabase CLI.
You can generate TypeScript types for a Supabase project using the Supabase CLI. This is useful when you make requests to your Supabase database and want to have types as part of your build process, and autocomplete in your editor.
First, you’ll need to find your project ID. You can find this in the Supabase dashboard. Then, run the following command in your terminal:
You can add this to your package.json
scripts:
This creates a types file in your src
directory (change as needed). Now, you can import the types file and pass it as a type parameter to your Supabase client while you instantiate it:
By doing this, every submethod and function in your Supabase client will now have types.
Here’s an example of the types generated for one of my projects, which has a table called discord_users
:
For more details on how this works, check out Supabase’s docs.