Skip to Content
DatabaseType Definitions

Type definitions

Generate TypeScript types from your database schema so the Supabase client can check table names, columns and query results.

Prerequisites

Apply your migrations before generating types. Run the commands from your app’s root directory with the Supabase CLI.

Generate types from your hosted project

Sign in to the CLI

supabase login

Generate the types

Copy your project reference from the Supabase Dashboard’s project settings. Replace <project-ref> in this command:

PROJECT_REF="<project-ref>" yarn supabase:db-types

The script writes src/lib/db/database.types.ts. The Supabase client in src/lib/supabase.ts imports its Database type.

Verify

Check that your changed tables or columns appear in the generated file, then run:

yarn typecheck

Update queries affected by the schema change. Commit the generated file alongside the migration so other developers use the same types.

Generate types from a local database

After applying migrations to your local Supabase stack, run:

supabase gen types --lang=typescript --local --schema public > src/lib/db/database.types.ts

Check the generated changes and run yarn typecheck as you would for a hosted project. Generate from the database you just migrated; an older hosted schema will not include unapplied local changes.

Do not edit database.types.ts by hand. Supabase’s type generation guide  describes the available CLI options.

Last updated on