Extending supabase.ts with custom typings
Most JavaScript-based projects use TypeScript as it prevents errors and makes application development much more resilient and stable. As stated in Chapter 2, Supabase can easily generate correct database types for you, derived from the table structure you have. For instance, a numeric primary key will be successfully derived as the TypeScript type number
, whereas the database text type will be derived as string
. Even a predefined enum will be properly derived as columnName: 'Value 1' | 'Value 2' | '...';
.
However, for json
/jsonb
types, Supabase cannot derive a proper type as the database doesn’t have rules for that. Any valid JSON will be allowed in a json
field. That’s why the type that is derived from Supabase for a json
field is as generic as this:
export type Json = | string | number | boolean | null | { [key: string]: Json | undefined...