Generating TypeScript Types from Supabase for Type-Safe Apps
Learn how to automatically generate TypeScript types from your Supabase database schema to keep your app type-safe and bug-free.

Faisal Husain
When working with Supabase and TypeScript, keeping your types in sync with your database is essential for type safety. Here’s a simple 2-step guide to generate types from your Supabase project.
Step 1: Get Your Supabase Access Token
- Go to your Supabase Dashboard.
- Click on your profile icon (top right) and select Account.
- Scroll down to Access Tokens.
- Click Generate New Token, give it a name (e.g., "typegen"), and copy the generated token.
Step 2: Generate Types Using the Supabase CLI
- Open your terminal.
- Log in with your access token:
supabase login --token YOUR_PASTED_TOKEN
- Generate the types (replace "projectid" with your actual project ref):
npx supabase gen types typescript --project-id **projectid** > lib/database.types.ts --debug
- Additionally you can write a script in package.json.
{
"scripts": {
"generate-types": "npx supabase gen types typescript --project-id **projectid** > lib/database.types.ts --debug"
}
}
Conclusion:
That’s it! You now have up-to-date TypeScript types for your Supabase schema. Use these types in your app for a safer and smoother development experience.