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.
- First have your supabase typescript file generated Supabase Docs
npx supabase gen types typescript --linked --schema public > ./src/schema.ts- Run the
better-supabase-typescommand!
npx better-supabase-types -i ./src/schema.ts -o ./src/newSchema.tsIf you would like to overwrite the input file with the better types output, you must supply the force flag (-f) to the generate command. In this scenario you won't need to provide the output option:
npx better-supabase-types -i ./src/schema.ts -f
If your project uses prettier and you would this tool to use your prettier config you can supply the -p flag and that will format your output according to the .prettierrc in your route file.
npx better-supabase-types -i ./src/schema.ts -o ./src/newSchema.ts -p .prettierrc
In the case that your prettier config file is not in the root of your project or is named .prettier.json, you can supply a value to the flag like this:
npx better-supabase-types -i ./src/schema.ts -o ./src/newSchema.ts -p ./configs/.prettier.json
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[] = [];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.