1. 10
    Generate TypeScript Definitions from PostgreSQL Schema with Supabase CLI
    4m 6s

Generate TypeScript Definitions from PostgreSQL Schema with Supabase CLI

InstructorJon Meyers

Share this video with your friends

Send Tweet

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 login

Generate TS definitions file

npx supabase gen types typescript --project-id your-project-id > lib/database.types.ts

Resources