types command reads your declarative schema tree and emits two output files: a database.types.ts file containing Supabase-compatible TypeScript interfaces, and a database.zod.ts file containing matching Zod validators. Because supaschema parses your schema files directly, you never need a live database connection to regenerate your types — your schema files are the source of truth.
How it works
supaschema types walks the schema source you point it at (by default the directories listed under schemaPaths in your config), builds an in-memory model of every table, view, enum, and composite type, then writes two files:
database.types.ts— the same shape that the Supabase CLI’sgen types typescriptcommand produces, so it drops in as a direct replacement. It exports aDatabaseinterface you pass directly tocreateClient<Database>.database.zod.ts— a matching set of Zod schemas derived from the same model, one schema per table row type, ready to use in API handlers and form validation.
You do not need a running database.
types is a pure static analysis step — it never opens a connection. Run it in CI after linting your schema files, before your build step.Auto-run with diff
You don’t have to invoke types manually after every schema change. The diff command calls it automatically once it has finished writing a new migration file. If you prefer to disable that behaviour, set autoTypes: false in your config.
Configuration
Two config keys control where the output files land:| Key | Default | Description |
|---|---|---|
typesFile | database.types.ts | Output path for the TypeScript types file |
zodFile | database.zod.ts | Output path for the Zod validators file |
supaschema.config.json.
Flags
The schema source to parse. Accepts the same source specifiers as
diff and inspect — for example dir:supabase/schemas or git:HEAD. Defaults to the first entry in schemaPaths from your config file.Override the output path for the TypeScript types file, or pass
stdout to print the types directly to standard output. When --out stdout is used, the Zod validators file is not written. Overrides typesFile from config.Path to a
supaschema.config.json file. Defaults to supaschema.config.json in the current working directory.Usage
Example output
Given aprofiles table and an order_status enum in your schema, the generated database.types.ts looks like this:
database.zod.ts exports a matching Zod schema for each row type:
Integrating with the Supabase client
Pass the generatedDatabase type to createClient and every query you write becomes fully type-checked:
Keeping types in sync in CI
Add atypes step after your schema lint step and before your build: