Home

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


_21
name: 'generate-types'
_21
on:
_21
pull_request:
_21
_21
jobs:
_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