Supabase
Generate TypeScript types from a Supabase schema
Generate types from your database schema in the Supabase dashboard or with the CLI. Use them with supabase-js for typed queries and inserts.
Documentation reviewed · 2 methods with sources
Ways to do it
- Interface: Supabase project dashboard → Generate TypeScript types
- CLI: supabase gen types typescript --remote
Interface
Supabase project dashboard → Generate TypeScript types
Generate and download TypeScript definitions for the selected project schema.
Read source: Supabase generating TypeScript types- Requirements
- Dashboard access to the Supabase project and its schema documentation.
- Limitations
- The output reflects the project schema at generation time. Regenerate it after relevant schema changes.
CLI
supabase gen types typescript --remote
Write generated definitions from a remote project schema to a TypeScript file.
Read source: Supabase CLI type generation workflow- Requirements
- The Supabase CLI, an initialized project, CLI login with a personal access token, and a project reference or linked project.
- Limitations
- Generation queries the selected schema. Set --schema to include the schemas your application uses, then regenerate after schema changes.
Example shell
npx supabase gen types typescript --remote="$PROJECT_REF" --schema public > database.types.ts