Getting Started
Installing
Initializing
Usage with TypeScript
Supabase-js ships with type definitions for usage with TypeScript and for convenient IntelliSense autocomplete and documentation in your editor.
When using TypeScript, you can pass the type of database row as a type parameter to the from
method to get better autocompletion support down the chain.
If you don't provide a type for the row you need to explicitly pass from<any>('tableName')
.
Generate database types from Swagger OpenAPI specification
Supabase generates a Swagger speficiation file for your database which can be used to generate your data types for usage with TypeScript.
The Swagger specification for your Supabase project can be accessed as follows:
Using the open source swagger-to-ts tool you can generate your types and store them locally:
Note: Do note that your local types won't automatically stay in sync with your database, so make sure to regenerate your types after your make changes to your database.
After you have generated your types, you can use them in your TypeScript projects:
Reference
createClient()
supabaseURL: string
The unique Supabase URL which is supplied when you create a new project in your project dashboard.
supabaseKey: string
The unique Supabase Key which is supplied when you create a new project in your project dashboard.