Skip to content

fix: Type regressions in ascending/descending fields - #2919

Open
swittk wants to merge 8 commits into
parse-community:alphafrom
swittk:fix-ascending-descending-types
Open

fix: Type regressions in ascending/descending fields#2919
swittk wants to merge 8 commits into
parse-community:alphafrom
swittk:fix-ascending-descending-types

Conversation

@swittk

@swittk swittk commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Issue

Typings for ascending, descending, addAscending, and addDescending in the current version are typed as ...string[], which misses the original object key checks which were possible in the original DefinitelyTyped typings.
This change allows for the autocompletion & key inference type checks to work once again (this includes base attributes such as objectId, createdAt, updatedAt too).
The comma-string keys (which are technically supported, JS-wise, but were not supported in the original DefinitelyTyped typings) are not included in this scope yet, but should be possible to add in a future PR by using modern features.

Approach

Used key inference in the same fashion as in the prior DefinitelyTyped typings.

Tasks

  • Add tests

Summary by CodeRabbit

  • Refactor
    • Improved type safety for query sorting and field selection to enhance compile-time validation and autocompletion. No runtime behavior changes.
  • New Features
    • Typings now explicitly permit the special full-text ranking key ($score) and common metadata fields (creation/update timestamps and object IDs) in query sorting and selection.
  • Tests
    • Extended type tests to cover the updated sorting and selection typings.

@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request!

@parseplatformorg

parseplatformorg commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Feb 13, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Tightened ParseQuery type signatures to include the special full-text ranking key '$score' for select/ascending variants, restricted descending variants, updated JSDoc, and changed sortByTextScore() to call this.select(['$score']) without an unsafe cast. Type tests and declaration files updated accordingly.

Changes

Cohort / File(s) Summary
Query implementation
src/ParseQuery.ts
Replaced this.select(['$score'] as any) with this.select(['$score']); adjusted method signatures/types and JSDoc for sorting/select/select-related logic.
Type declarations
types/ParseQuery.d.ts
Expanded generic parameter constraints to allow '$score' for ascending/addAscending/select; changed parameter shapes to `(K
Type tests
types/tests.ts
Added/updated type tests to accept metadata fields (e.g., createdAt, updatedAt, objectId) in sort methods and '$score' in select; added positive assertions for ParseQuery<MySubClass>.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mtrezza
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix: Type regressions in ascending/descending fields' uses the required 'fix:' prefix and accurately describes the main change: fixing type regressions in ordering/selection methods.
Description check ✅ Passed The PR description includes the Issue section (explaining the typing regression and the fix scope), the Approach section (describing the solution), and indicates tests were added. All critical sections are present and complete.
Security Check ✅ Passed Pull request contains only TypeScript type definition updates with no runtime behavior changes, removes unsafe type casts, and adds comprehensive test coverage.
Engage In Review Feedback ✅ Passed Git commit history shows author engaged with review feedback through iterative commits on Apr 10, explicitly revising scope and completing missing functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ParseQuery.ts (1)

1566-1570: ⚠️ Potential issue | 🟠 Major

sortByTextScore will fail to compile with the new ascending constraint.

'$score' is not a member of keyof T['attributes'] | keyof BaseAttributes, so this.ascending('$score') on line 1567 will produce a type error after this change. The select call already works around this with as any, but ascending does not.

Proposed fix
   sortByTextScore() {
-    this.ascending('$score');
+    this.ascending('$score' as any);
     this.select(['$score'] as any);
     return this;
   }
🤖 Fix all issues with AI agents
In `@types/ParseQuery.d.ts`:
- Line 737: The new key constraint on
ascending/descending/addAscending/addDescending is too strict and breaks
sortByTextScore(), which calls this.ascending('$score'); relax the signatures in
types/ParseQuery.d.ts (the ascending, descending, addAscending, addDescending
declarations) to allow special string keys (either include | string or
explicitly include the literal '$score') in addition to keyof T['attributes'] |
keyof BaseAttributes so calls like this.ascending('$score') compile without
casts; update the declarations to accept (K | string | K[])[] or add an overload
that accepts string | string[] to preserve type safety for attribute keys while
supporting '$score'.

Comment thread types/ParseQuery.d.ts Outdated
@codecov

codecov Bot commented Feb 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.98%. Comparing base (17ceef1) to head (d29b7b3).
⚠️ Report is 4 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #2919   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files          64       64           
  Lines        6339     6339           
  Branches     1522     1538   +16     
=======================================
  Hits         6338     6338           
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
types/ParseQuery.d.ts (1)

747-764: ⚠️ Potential issue | 🟡 Minor

'$score' is missing from addAscending, descending, and addDescending constraints.

ascending and select include '$score' in their generic constraint, but the other three sort methods do not. A user who writes query.addAscending('$score') or query.descending('$score') will get a type error, even though the runtime accepts it. If the omission is intentional (only the ascending('$score') pattern is officially supported), a brief JSDoc note on these methods would help; otherwise, add | '$score' for consistency.

Proposed fix for consistency
-    addAscending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
+    addAscending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;
...
-    descending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
+    descending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;
...
-    addDescending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
+    addDescending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;

coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 13, 2026
Comment thread src/ParseQuery.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/ParseQuery.ts (1)

1771-1784: ⚠️ Potential issue | 🟡 Minor

Align addAscending with ascending for '$score' support.

ascending accepts '$score', but it delegates to addAscending, whose public signature rejects '$score'. This creates an avoidable API/type inconsistency for equivalent runtime behavior.

Suggested fix
-  addAscending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
+  addAscending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this {

Use this read-only verification to confirm the signature gap and test coverage status:

#!/bin/bash
# Verify '$score' typing across sorting methods and type tests.
rg -n "ascending<|addAscending<|descending<|addDescending<|select<" src/ParseQuery.ts types/ParseQuery.d.ts
rg -n "\$score" types/tests.ts -C2
rg -n "addAscending\\('\\$score'\\)|addDescending\\('\\$score'\\)" types/tests.ts -C2
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ParseQuery.ts` around lines 1771 - 1784, addAscending's generic signature
currently excludes '$score' while ascending accepts it and delegates to
addAscending, causing a typing mismatch; update addAscending (and symmetrically
addDescending if present) to include '| '$score'' in its generic constraint
(match ascending/descending signatures) so both runtime and type APIs align,
then run the provided grep/type-test commands to verify '$score' is accepted in
addAscending/addDescending and tests/types compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/ParseQuery.ts`:
- Around line 1771-1784: addAscending's generic signature currently excludes
'$score' while ascending accepts it and delegates to addAscending, causing a
typing mismatch; update addAscending (and symmetrically addDescending if
present) to include '| '$score'' in its generic constraint (match
ascending/descending signatures) so both runtime and type APIs align, then run
the provided grep/type-test commands to verify '$score' is accepted in
addAscending/addDescending and tests/types compile.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ee3840e-a23d-40df-8fb3-08d20237b98d

📥 Commits

Reviewing files that changed from the base of the PR and between ef96ed2 and c24f2d3.

📒 Files selected for processing (1)
  • src/ParseQuery.ts

coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 10, 2026
@swittk

swittk commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

I think this is ready to merge

@mtrezza

mtrezza commented Apr 10, 2026

Copy link
Copy Markdown
Member

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/ParseQuery.ts (1)

1830-1869: Optional: document that $score is intentionally excluded from descending.

The descending pair correctly excludes '$score' from its key constraint (full-text ranking is only meaningful in ascending order for this API). Consider a one-line JSDoc note mirroring the ascending doc so consumers understand this is intentional rather than an omission, e.g.:

📝 Proposed JSDoc clarification
   /**
    * Sorts the results in descending order by the given key.
-   *
+   * Note: `$score` is not supported here; full-text score ranking must use `ascending('$score')`.
    * `@param` {(string|string[])} keys The key to order by, which is a
    * string of comma separated values, or an Array of keys, or multiple keys.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ParseQuery.ts` around lines 1830 - 1869, Add a one-line JSDoc note to the
descending (and/or addDescending) method(s) clarifying that '$score' is
intentionally excluded from the allowed keys because full-text ranking only
applies in ascending order for this API; update the comment block above
descending (and mirror in addDescending if present) to reflect this intentional
behavior so consumers don't think it's an omission, referencing the descending
and addDescending methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/ParseQuery.ts`:
- Around line 1830-1869: Add a one-line JSDoc note to the descending (and/or
addDescending) method(s) clarifying that '$score' is intentionally excluded from
the allowed keys because full-text ranking only applies in ascending order for
this API; update the comment block above descending (and mirror in addDescending
if present) to reflect this intentional behavior so consumers don't think it's
an omission, referencing the descending and addDescending methods.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8fc96cb5-38ab-461e-b8e6-99e5c84b0b5b

📥 Commits

Reviewing files that changed from the base of the PR and between c08460f and d29b7b3.

📒 Files selected for processing (2)
  • src/ParseQuery.ts
  • types/ParseQuery.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • types/ParseQuery.d.ts

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.

3 participants