Skip to content

fix(postgrest): add type safety for eq() and neq() column names#2175

Merged
mandarini merged 2 commits intosupabase:masterfrom
aayushbaluni:fix/43381-eq-type-safety
Mar 23, 2026
Merged

fix(postgrest): add type safety for eq() and neq() column names#2175
mandarini merged 2 commits intosupabase:masterfrom
aayushbaluni:fix/43381-eq-type-safety

Conversation

@aayushbaluni
Copy link
Copy Markdown
Contributor

@aayushbaluni aayushbaluni commented Mar 17, 2026

Fixes supabase/supabase#43381, Adds type safety to eq() and neq() for column names.

Builds on the original approach from @aayushbaluni, but uses a conditional type on the column parameter instead of overloads. The overload pattern doesn't actually reject invalid literals, they silently fall through to the eq(column: string, value: unknown) fallback. The conditional type approach closes that hole.

How it works:

Call Result
.eq('username', 'foo') typed value
.eq('INVALID', 'x') TS error not a valid column
.eq('users.status', 'ONLINE') relationship filter
.eq('bar->version', 31) JSON path filter
const col: string; .eq(col, x) dynamic variable passes through

Also fixes a latent type error in relationships-error-handling.test.ts where .eq('id', 2) was called on the users table (which has no id column). This was previously masked by the fallback overload.

@aayushbaluni aayushbaluni requested review from a team as code owners March 17, 2026 16:16
@aayushbaluni aayushbaluni force-pushed the fix/43381-eq-type-safety branch from 0dc4012 to 5762d1f Compare March 18, 2026 06:08
@mandarini mandarini changed the title fix(postgrest-js): add type safety for eq() and neq() column names fix(postgrest): add type safety for eq() and neq() column names Mar 20, 2026
aayushbaluni and others added 2 commits March 20, 2026 17:23
Add overloads to eq() and neq() matching gt/gte/lt/lte pattern:
- Strict overload: column must extend keyof Row for autocomplete and
  invalid column name detection
- Fallback overload: column: string for dynamic usage

Fixes supabase/supabase#43381
@mandarini mandarini force-pushed the fix/43381-eq-type-safety branch from 5762d1f to 9325928 Compare March 20, 2026 15:49
@mandarini mandarini self-assigned this Mar 20, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2175

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2175

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2175

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2175

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2175

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2175

commit: 9325928

@steve-chavez steve-chavez requested a review from avallete March 23, 2026 14:43
Copy link
Copy Markdown
Member

@steve-chavez steve-chavez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍. Essentially ensuring the first arg of the eq() is always a column name.

@mandarini mandarini merged commit 15254fa into supabase:master Mar 23, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: .eq() filter lacks type safety for column names

3 participants