Skip to content

fix(postgrest): correct order() overload typing for referenced tables#2025

Open
DevanshTyagi04 wants to merge 1 commit intosupabase:masterfrom
DevanshTyagi04:fix/order-foreign-table-types
Open

fix(postgrest): correct order() overload typing for referenced tables#2025
DevanshTyagi04 wants to merge 1 commit intosupabase:masterfrom
DevanshTyagi04:fix/order-foreign-table-types

Conversation

@DevanshTyagi04
Copy link

@DevanshTyagi04 DevanshTyagi04 commented Jan 16, 2026

🔍 Description

This PR fixes TypeScript overload typing for the order() method when used with referenced tables in postgrest-js.

What changed?

  • Corrected the order() method overload typings to properly support referencedTable
  • Ensured deprecated foreignTable typing remains backward-compatible
  • Improved type inference without changing runtime behavior

Why was this change needed?

The existing overloads caused incorrect or confusing TypeScript inference when ordering by referenced tables, even though the feature works correctly at runtime. This fix aligns the type definitions with actual PostgREST behavior and improves developer experience.

Closes #971

📸 Screenshots/Examples

No UI changes. Type-level fix only.

🔄 Breaking changes

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format
  • I have run npx nx format
  • No new runtime logic introduced; existing tests cover behavior
  • No documentation updates required

📝 Additional notes

This change is limited to type definitions and does not affect runtime behavior or generated queries.

@DevanshTyagi04 DevanshTyagi04 requested review from a team as code owners January 16, 2026 10:56
@mandarini mandarini self-assigned this Feb 4, 2026
@coveralls
Copy link

Coverage Status

coverage: 80.997%. remained the same
when pulling 56045b7 on DevanshTyagi04:fix/order-foreign-table-types
into 09aa106 on supabase:master.

Comment on lines -75 to -89
order<ColumnName extends string & keyof Row>(
column: ColumnName,
options?: { ascending?: boolean; nullsFirst?: boolean; referencedTable?: undefined }
): this
order(
column: string,
options?: { ascending?: boolean; nullsFirst?: boolean; referencedTable?: string }
): this
/**
* @deprecated Use `options.referencedTable` instead of `options.foreignTable`
*/
order<ColumnName extends string & keyof Row>(
column: ColumnName,
options?: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: undefined }
): this
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this will produce the intended behavior. @avallete Could you help review 🙏 ?

Copy link
Member

Choose a reason for hiding this comment

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

The overload are here to hint Typescript into correct auto-completion. Without this I think you'll never have autocomplete within the function arg 🤔

Copy link
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

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

What's the underneath issue being resolved here ? The type overrides are here to allow autocompletion of the column name by typescript if it extends a column in infered Row.

If it doesn't, they you're still allowed to use a pure string.

@mandarini mandarini self-requested a review February 19, 2026 15:43
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.

Order on a foreign table

5 participants