A CLI tool to add exports for your supabase tables. It will add type exports at the bottom of a new typescript file of every table you have. This tool can help remove the need to make a type for their rows manually.
import { Database } from './src/schema.ts';
type Todo = Database['public']['Tables']['Todo']['Row'];
const todos: Todo[] = [];
import { Todo } from './src/newSchema.ts';
const todos: Todo[] = [];
npx supabase gen types typescript --linked --schema public > ./src/schema.ts
better-supabase-types
command (you can also use a config file):npx better-supabase-types -i ./src/schema.ts -o ./src/newSchema.ts
Options:
--version Show version number [boolean]
--help Show help [boolean]
-i, --input Path to the input file [string] [required]
-o, --output Path to the output file [string]
-p, --prettier Path to the prettier config file
[string] [default: ".prettierrc"]
-f, --force Force the overwrite of the input file [boolean]
-s, --singular Convert table names to singular form instead of plural form
[boolean] [default: false]
--enumAsType Have converted enums defined as types and not enums
[boolean] [default: false]
--enumPascalCase Enums format to pascal case [boolean] [default: false]
You can also use a config named .betterrc.json
:
{
"input": "./src/schema.ts",
"force": true,
"singular": true
}
You can also put your config file in your package.json
file:
{
"name": "better-supabase-types",
"...": "...",
"betterConfig": {
"input": "./schema.ts",
"output": "./newSchema.ts"
}
}
Please contribute to this if you find any bugs or want any additions. This is my first public package so please bear with me if there are any issues.
Big thanks to Barry for making the Supabase React Query Codegen tool to help me understand on how to read the supabase type file.