Skip to content

Commit 4d35d26

Browse files
authored
feat: add query result type helpers. (#918)
* feat: add query result type helpers. * chore: update naming for consiceseness.
1 parent 3bc5723 commit 4d35d26

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export {
1717
} from '@supabase/functions-js'
1818
export * from '@supabase/realtime-js'
1919
export { default as SupabaseClient } from './SupabaseClient'
20-
export type { SupabaseClientOptions } from './lib/types'
20+
export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from './lib/types'
2121

2222
/**
2323
* Creates a new Supabase Client.

src/lib/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GoTrueClient } from '@supabase/gotrue-js'
22
import { RealtimeClientOptions } from '@supabase/realtime-js'
3+
import { PostgrestError } from '@supabase/postgrest-js'
34

45
type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]
56

@@ -95,3 +96,10 @@ export type GenericSchema = {
9596
Views: Record<string, GenericView>
9697
Functions: Record<string, GenericFunction>
9798
}
99+
100+
/**
101+
* Helper types for query results.
102+
*/
103+
export type QueryResult<T> = T extends PromiseLike<infer U> ? U : never
104+
export type QueryData<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
105+
export type QueryError = PostgrestError

0 commit comments

Comments
 (0)