Typescript Support
supabase-js
supports Typescript.
Generating types#
You can use our CLI to generate types:
These types are generated directly from your database.
There is a difference between selects
, inserts
, and updates
, because often you will set default values in your database for specific columns.
With default values you do not need to send any data over the network, even if that column is a "required" field. Our type system is granular
enough to handle these situations.
Given a table public.movies
, the definition will provide the following data:
Injecting type definitions#
You can enrich the supabase client with the types you generated with Supabase.
Type hints#
supabase-js
always returns a data
object (for success), and an error
response (for unsuccessful requests).
This provides a simple interface to get the relevant types returned from any function:
_10 export async function getMovies() {_10 return await supabase.from('movies').select(`id, title`)_10 }_10_10 type MoviesResponse = Awaited<ReturnType<typeof getMovies>>_10 export type MoviesResponseSuccess = MoviesResponse['data']_10 export type MoviesResponseError = MoviesResponse['error']
Nested tables#
For advanced queries such as nested tables, you may want to construct your own types.