Generate types using GitHub Actions
End-to-end type safety across client, server, and database.
You can use the Supabase CLI to automatically generate Typescript definitions from your Postgres database. You can then pass these definitions to your supabase-js client and get end-to-end type safety across client, server, and database.
Inside your repository, create a new file inside the .github/workflows folder called generate-types.yml. Copy this snippet inside the file, and the action will run whenever a new PR is created:
Verify types
1name: 'generate-types'2on:3 pull_request:45jobs:6 build: 7 runs-on: ubuntu-latest8 steps:9 - uses: supabase/setup-cli@v110 with:11 version: latest12 - run: supabase init13 - run: supabase db start14 - name: Verify generated types match Postgres schema15 run: |16 supabase gen types typescript --local > schema.gen.ts17 if ! git diff --ignore-space-at-eol --exit-code --quiet schema.gen.ts; then18 echo "Detected uncommitted changes after build. See status below:"19 git diff20 exit 121 fiMore resources
- Using supabase-js with type definitions: Typescript Support