Skip to content

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

@aristotelis96

Description

@aristotelis96

Bug report

Describe the bug

There appears to be a regression in the TypeScript definitions for the Postgrest filter methods, specifically .eq(). Previously, the first argument (the column name) was strictly typed based on the schema of the table selected in .from().

Currently, .eq() is accepting arbitrary string values for the column name without throwing a TypeScript error, even when the column does not exist on the table.

To Reproduce

Schema Context:
Assume a table profiles exists with columns id, avatar_url and username.

import { createBrowserClient } from "@supabase/ssr"

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL as string
const supabasePubKey = process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY as string

type Database = {
    public: {
        Tables: {
            profiles: {
                Row: {
                    id: string
                    avatar_url: string | null
                    username: string | null
                }
                Insert: {
                    id: string
                    avatar_url?: string | null
                    username?: string | null
                }
                Update: {
                    id?: string
                    avatar_url?: string | null
                    username?: string | null
                }
                Relationships: []
            }
        }
        Views: {}
        Functions: {
            authorize: {
                Args: {
                    requested_permission: Database["public"]["Enums"]["app_permission"]
                }
                Returns: boolean
            }
        }

        CompositeTypes: {
            [_ in never]: never
        }
    }
}

export const supabase = createBrowserClient<Database>(supabaseUrl, supabasePubKey)
supabase.from("profiles").select("*").eq("INVALID", "test")

Observed Behavior:

The code above compiles successfully. The compiler allows "non_existent_column" (or any string) as the first argument to .eq().

Expected Behavior:

TypeScript should raise an error indicating that "non_existent_column" does not exist on the profiles table, similar to how it behaves for .select() or .update().

Additional notes:

.from() and .gt(),.gte(),.lt(),.lte() behave as expected and are typesafe

System information

  • OS: [macOS, but tried on Ubuntu 22.04 as welll]

  • Version of supabase:

    • "@supabase/ssr": "^0.5.2",
    • "@supabase/supabase-js": "^2.48.4",
      But tried also with the latest ssr 0.9.0 and supabase-js 2.98.0, issue remains
  • Version of Node.js: v20.17.0

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions