Open mikeschneiderdotme opened 1 year ago
I've got the exact same issue:
I've noticed the various PostgrestBuilder objects aren't noticing the typings, however the supabase client object is:
Oddly enough, if I specify the columns manually the types carry over fine, but not when using the wildcard *
Any insight would be greatly appreciated.
Same here. Doesn't work with the Supabase docs' suggestions either.
const supabase = createClient<Database>(supabaseUrl, supabaseKey);
export function modelStoreFactory<T extends keyof Database['public']['Tables']>(tableName: string) {
const tbl = supabase.from(tableName);
type TRow = Database['public']['Tables'][T]['Row'];
type TInsert = Database['public']['Tables'][T]['Insert'];
async function insertItem(item: TInsert): Promise<TRow> {
const result: PostgrestSingleResponse<TRow> = await tbl.insert(item).select();
}
}
Result:
1. Type 'PostgrestSingleResponse<any[]>' is not assignable to type 'PostgrestSingleResponse<TRow>'.
Type 'PostgrestResponseSuccess<any[]>' is not assignable to type 'PostgrestSingleResponse<TRow>'.
Type 'PostgrestResponseSuccess<any[]>' is not assignable to type 'PostgrestResponseSuccess<TRow>'.
Type 'any[]' is not assignable to type 'TRow'.
Edit: The Supabase JS Client docs were not super clear on this, but I fixed the error in this case by using .limit(1).single()
to return only one updated object, as I expected.
Bug report
Describe the bug
When querying the database context in Typescript, the data returned is always of type
any
instead inferring the correct type from the injected database types. Previously, the correct types would be returned in the data object.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
const { data, error } = supabaseClient.from('authors').select()
data
object typeExpected behavior
The expected behavior, and what previously happened, is that the
data
object type would be correctly inferred as anAuthor[]
object based on injected data types. Instead thedata
object is of type `any[]Screenshots
System information