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
_21name: 'generate-types'_21on:_21 pull_request:_21_21jobs:_21 build: _21 runs-on: ubuntu-latest_21 steps:_21 - uses: supabase/setup-cli@v1_21 with:_21 version: latest_21 - run: supabase init_21 - run: supabase db start_21 - name: Verify generated types match Postgres schema_21 run: |_21 supabase gen types typescript --local > schema.gen.ts_21 if ! git diff --ignore-space-at-eol --exit-code --quiet schema.gen.ts; then_21 echo "Detected uncommitted changes after build. See status below:"_21 git diff_21 exit 1_21 fi
More resources
- Using supabase-js with type definitions: Typescript Support