Course lesson
Generate TypeScript Definitions from PostgreSQL Schema with Supabase CLI
Typescript reduces runtime errors and makes our code more maintainable. Supabase allows us to introspect our PostgreSQL schema and generate TypeScript definitions.
- Duration
- 4 min
- Access
- Free
- Transcript
- Retained from source evidence
Typescript reduces runtime errors and makes our code more maintainable. Supabase allows us to introspect our PostgreSQL schema and generate TypeScript definitions.
In this lesson we generate an access token to use the Supabase CLI and generate TypeScript definitions. Additionally, we write our types to a file, which can be passed to our Supabase client, giving our application full type-safety across client, server and database.
Lastly, we make our Database types globally available so we don't need to import them every time we create a Supabase client.
Code Snippets
Login to Supabase CLI
npx supabase loginGenerate TS definitions file
npx supabase gen types typescript --project-id your-project-id > lib/database.types.ts