You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need to declare the table name multiple times (prone to mistyping the table name)
The input to from is not checked (e.g., you could time from('tables') for the above snippet and it would not fail linting)
But what if the definitions were added to the supabase client instead?
// lib file to create the clientimport{createClient}from'@supabase/supabase-js'exportconstsupabase=createClient<definitions>(supabaseUrl,supabaseKey)// file where you use the clientsupabase.from('table').select('*')
Then, you could be confident in your static type checking:
No need to duplicate the table name in the from function
It's guaranteed that all database calls are type checked
The from input could be type-checked (i.e., it's just the keyof definitions)
Cleaner code syntax all around
Added benefit that in VS Code, you get autocomplete on the table names, making the code more self-documenting
The text was updated successfully, but these errors were encountered:
This is actually a lot cleaner - but I might need a TS expert to investigate how difficult it is to implement. I'll transfer this one to our postgrest-js repo for now 👍
Feature request
First off, it's great that I can use TypeScript to statically type check everything. I think the syntax could be improved, though.
Right now, you need to add the definitions to every database operation:
This works, but isn't optimal for a few reasons:
from
callfrom
is not checked (e.g., you could timefrom('tables')
for the above snippet and it would not fail linting)But what if the definitions were added to the supabase client instead?
Then, you could be confident in your static type checking:
from
functionfrom
input could be type-checked (i.e., it's just thekeyof definitions
)The text was updated successfully, but these errors were encountered: