diff --git a/apps/docs/docs/ref/javascript/typescript-support.mdx b/apps/docs/docs/ref/javascript/typescript-support.mdx index 0a3163d2572..021617ff9a7 100644 --- a/apps/docs/docs/ref/javascript/typescript-support.mdx +++ b/apps/docs/docs/ref/javascript/typescript-support.mdx @@ -158,21 +158,13 @@ const { data } = await supabase.from('countries').select().returns() - It's convenient to have shorthands for your most-used types. + The generated types provide shorthands for accessing tables and enums. - ```ts ./database.types.ts - import { Database } from "./database-generated.types.ts"; - export type { Database } from "./database-generated.types.ts"; - - export type Tables = Database['public']['Tables'][T]['Row'] - export type Enums = Database['public']['Enums'][T] - // etc. - ``` ```ts ./index.ts - import { Database, Tables } from "./database.types.ts"; + import { Database, Tables, Enums } from "./database.types.ts"; // Before 😕 let movie: Database['public']['Tables']['movies']['Row'] = // ... @@ -210,23 +202,21 @@ const { data } = await supabase.from('countries').select().returns() - ```ts - import { PostgrestError } from '@supabase/supabase-js' - - export type DbResult = T extends PromiseLike ? U : never - export type DbResultOk = T extends PromiseLike<{ data: infer U }> ? Exclude : never - export type DbResultErr = PostgrestError - ``` ```ts - const countriesWithCitiesQuery = supabase.from("countries").select( - ` - id, - name, - cities ( id, name ) - ` - ); - type CountriesWithCities = DbResultOk; + import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js' + + const countriesWithCitiesQuery = supabase + .from("countries") + .select(` + id, + name, + cities ( + id, + name + ) + `); + type CountriesWithCities = QueryData; const { data, error } = await countriesWithCitiesQuery; if (error) throw error; diff --git a/apps/docs/pages/guides/api/joins-and-nesting.mdx b/apps/docs/pages/guides/api/joins-and-nesting.mdx index 0eeb9f961eb..fb9f91471ee 100644 --- a/apps/docs/pages/guides/api/joins-and-nesting.mdx +++ b/apps/docs/pages/guides/api/joins-and-nesting.mdx @@ -113,22 +113,17 @@ create table cities ( We can get the nested `CountriesWithCities` type like this: ```ts -import { PostgrestError } from '@supabase/supabase-js' +import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js' -export type DbResult = T extends PromiseLike ? U : never -export type DbResultOk = T extends PromiseLike<{ data: infer U }> ? Exclude : never -export type DbResultErr = PostgrestError -``` - -```ts -const countriesWithCitiesQuery = supabase.from('countries').select( - ` +const countriesWithCitiesQuery = supabase.from('countries').select(` id, name, - cities ( id, name ) -` -) -type CountriesWithCities = DbResultOk + cities ( + id, + name + ) +`) +type CountriesWithCities = QueryData const { data, error } = await countriesWithCitiesQuery if (error) throw error diff --git a/apps/docs/pages/guides/api/rest/generating-types.mdx b/apps/docs/pages/guides/api/rest/generating-types.mdx index 2f4aad081f9..ac14bc5ba50 100644 --- a/apps/docs/pages/guides/api/rest/generating-types.mdx +++ b/apps/docs/pages/guides/api/rest/generating-types.mdx @@ -129,20 +129,10 @@ const { data } = await supabase.from('countries').select().returns() ### Type shorthands -It's convenient to have shorthands for your most-used types. - -```ts ./database.types.ts -import { Database } from './database-generated.types.ts' -export type { Database } from './database-generated.types.ts' - -export type Tables = - Database['public']['Tables'][T]['Row'] -export type Enums = Database['public']['Enums'][T] -// etc. -``` +The generated types provide shorthands for accessing tables and enums. ```ts ./index.ts -import { Database, Tables } from "./database.types.ts"; +import { Database, Tables, Enums } from "./database.types.ts"; // Before 😕 let movie: Database['public']['Tables']['movies']['Row'] = // ... @@ -175,22 +165,17 @@ create table cities ( We can get the nested `CountriesWithCities` type like this: ```ts -import { PostgrestError } from '@supabase/supabase-js' +import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js' -export type DbResult = T extends PromiseLike ? U : never -export type DbResultOk = T extends PromiseLike<{ data: infer U }> ? Exclude : never -export type DbResultErr = PostgrestError -``` - -```ts -const countriesWithCitiesQuery = supabase.from('countries').select( - ` +const countriesWithCitiesQuery = supabase.from('countries').select(` id, name, - cities ( id, name ) -` -) -type CountriesWithCities = DbResultOk + cities ( + id, + name + ) +`) +type CountriesWithCities = QueryData const { data, error } = await countriesWithCitiesQuery if (error) throw error