fix(supabase): relax db schema type constraints in createClient options - #2476
fix(supabase): relax db schema type constraints in createClient options#2476gourabsingha1 wants to merge 2 commits into
Conversation
mandarini
left a comment
There was a problem hiding this comment.
Hi @gourabsingha1, thank you so much for contributing to Supabase! Really appreciate you digging into #969, it's a genuinely confusing error to hit.
One thing to flag before this can merge: relaxing db.schema to string removes the type checking for everyone, including the two-generic form (createClient<Database, 'personal'>(...)) where it currently works correctly and catches typos. It also doesn't fully solve the original problem, since with only createClient<Database>(...), the client's .from() calls will still be typed against public even though db.schema is set to personal at runtime. So the fix trades a compile error for a silent mismatch between the configured schema and the query types.
The good news is there's already a fully type-safe way to do this: supabase.schema('personal').from(...), which infers its type directly from the call. Would you be up for either narrowing this to only relax the type where inference genuinely can't help, or pivoting the PR toward pointing users at .schema() (docs and maybe a better error message) instead? Happy to help think through either direction.
Thank you again for taking the time to contribute, contributions like this are exactly how we find the rough edges worth smoothing out.
7a4a081 to
d4397d9
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@mandarini Thanks for the feedback! I updated the type signature to use |
This PR fixes a bug (Issue #969) where TypeScript displays a type error when attempting to initialize a client with a custom database schema under
db.schema, unless the user explicitly passes the schema as the second generic parameter tocreateClient. Because of the lack of partial generic inference in TypeScript, when only the first generic parameter<Database>is supplied, the second generic parameter (SchemaName) defaults to'public', restricting the type of thedb.schemaoption to'public'. This PR relaxes theschemaoption type underdbtostringso that initialization compiles successfully, while preserving type-safety of database/schema queries.