Skip to main content

Generating Types

Supabase will soon release native type generators that dump your database types for various languages. For now, we support TypeScript through third-party tools.

Usage with TypeScript

supabase-js ships with type definitions for usage with TypeScript and for convenient IntelliSense auto-complete 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 auto-completion support down the chain. If you don't provide a type for the row you need to explicitly pass from<any>('tableName').

type Message = {
id: number;
inserted_at: string;
message: string;
user_id: string;
channel_id: number;
author: { username: string };
}

const response = await supabase
.from<Message>('messages') // Message maps to the type of the row in your database.
.select('*, author:user_id(username)')
.match({ channel_id: 2 }) // Your IDE will be able to help with auto-completion.
response.data // Response data will be of type Array<Message>.

// If you don't provide a type for the row you need to explicitly pass `from<any>('tableName')`.
const response = await supabase
.from<any>('messages')
.select('*, author:user_id(username)')
.match({ channel_id: 2 })
response.data // Response data will be of type Array<any>.