Skip to content

Conversation

mdm317
Copy link

@mdm317 mdm317 commented Sep 14, 2025

fixes: #9016

  • Ensure type narrowing works after isSuccess, isPending, isError with initial data
  • Add test cases for isPending, isError when initial data is not provided

Summary by CodeRabbit

  • New Features

    • Improved TypeScript developer experience for infinite queries: results now support state-based type narrowing with query state guards (success, pending, error), providing more accurate types for data and error.
  • Tests

    • Reorganized and expanded test coverage for infinite queries, adding scenarios for success, pending, and error states with and without initial data to validate type-narrowing behavior.

Copy link
Contributor

coderabbitai bot commented Sep 14, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The update adds BaseQueryNarrowing to DefinedCreateInfiniteQueryResult in types, enabling type guards on injectInfiniteQuery results. Tests are restructured and expanded to validate isSuccess, isPending, and isError narrowing with and without initialData. No runtime code or public API signatures beyond the type alias composition changed.

Changes

Cohort / File(s) Summary
Type system update
packages/angular-query-experimental/src/types.ts
Updated DefinedCreateInfiniteQueryResult to BaseQueryNarrowing<TData, TError> & MapToSignals<TDefinedInfiniteQueryObserver> to support query-state type narrowing.
Tests for type narrowing
packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts
Reorganized tests into without/with initialData groups; added assertions for isSuccess, isPending, and isError to verify correct narrowing of data() and error().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

In burrows of code where types align,
I thump my paw at compile-time shine.
isSuccess? Hop! Data’s clearly there—
isPending, isError—handled with care.
With signals mapped and narrows true,
This bunny ships a crisp “type” brew. 🐇✨

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The change to include BaseQueryNarrowing in DefinedCreateInfiniteQueryResult alongside MapToSignals, together with added tests for isSuccess/isPending/isError with and without initialData, directly addresses the coding objectives of [#9016] by enabling and verifying that injectInfiniteQuery narrows data() after runtime guards; these are type-level and test-only changes and do not alter public runtime APIs. The provided test additions exercise the intended narrowing behaviors, so the linked issue's requirements are met by this changeset.
Out of Scope Changes Check ✅ Passed All modifications in the summary are limited to packages/angular-query-experimental/src/types.ts and the inject-infinite-query test file and are directly related to implementing and verifying type-narrowing behavior; there are no unrelated code changes or public API signature modifications in the provided diff. Accordingly, no out-of-scope changes were detected.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title concisely and accurately summarizes the primary change: fixing injectInfiniteQuery's type narrowing when initial data is provided; this aligns with the types.ts change that adds BaseQueryNarrowing to DefinedCreateInfiniteQueryResult and the updated tests that verify isSuccess/isPending/isError behavior with and without initialData.

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.

@mdm317 mdm317 changed the title fix: narrow injectInfiniteQuery type with initial data fix(angular-query): fix injectInfiniteQuery to narrow type Sep 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/angular-query-experimental/src/types.ts (1)

160-161: Style: spacing/formatting nits

Missing space after = and inconsistent indentation compared to neighboring aliases. Run the formatter or align manually (also covered by the diff above).

packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts (2)

26-77: Good coverage for narrowing without initialData

The three cases correctly validate narrowing behavior: data undefined on isPending, data defined on isSuccess, and error defined on isError.

Consider adding one negative assertion outside guards to ensure data() is InfiniteData<string, unknown> | undefined by default (no initialData).


79-141: Excellent: with initialData, pending still yields defined data

These tests capture the critical regression vector: isPending should still expose defined data() when initialData is present. The added isSuccess/isError checks round it out nicely.

Optionally assert that data() remains defined in the isError branch with initialData, mirroring runtime behavior.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6492aed and e3b11c0.

📒 Files selected for processing (2)
  • packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts (1 hunks)
  • packages/angular-query-experimental/src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts (1)
packages/query-core/src/types.ts (1)
  • InfiniteData (204-207)
packages/angular-query-experimental/src/types.ts (1)
packages/angular-query-experimental/src/signal-proxy.ts (1)
  • MapToSignals (4-6)
🔇 Additional comments (1)
packages/angular-query-experimental/src/types.ts (1)

160-161: Sanity-check complete — omission of BaseQueryNarrowing flags is correct
packages/query-core/src/types.ts defines isError/isPending/isSuccess; packages/angular-query-experimental/src/types.ts uses MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>> to drop those keys — no change required.

Comment on lines 160 to 161
> =BaseQueryNarrowing<TData, TError> &
MapToSignals<TDefinedInfiniteQueryObserver>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent key collisions with BaseQueryNarrowing in DefinedCreateInfiniteQueryResult

MapToSignals<TDefinedInfiniteQueryObserver> may reintroduce properties like isSuccess/isError/isPending (as Signals) that collide with the function-based guards from BaseQueryNarrowing, leading to incompatible intersections. Other aliases (e.g., CreateBaseQueryResult, DefinedCreateQueryResult) avoid this via OmitKeyof<..., keyof BaseQueryNarrowing, 'safely'>. Do the same here.

Apply this diff:

-export type DefinedCreateInfiniteQueryResult<
+export type DefinedCreateInfiniteQueryResult<
   TData = unknown,
   TError = DefaultError,
   TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<
     TData,
     TError
   >,
-> =BaseQueryNarrowing<TData, TError> &
- MapToSignals<TDefinedInfiniteQueryObserver>
+> = BaseQueryNarrowing<TData, TError> &
+  MapToSignals<OmitKeyof<TDefinedInfiniteQueryObserver, keyof BaseQueryNarrowing, 'safely'>>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
> =BaseQueryNarrowing<TData, TError> &
MapToSignals<TDefinedInfiniteQueryObserver>
export type DefinedCreateInfiniteQueryResult<
TData = unknown,
TError = DefaultError,
TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<
TData,
TError
>,
> = BaseQueryNarrowing<TData, TError> &
MapToSignals<OmitKeyof<TDefinedInfiniteQueryObserver, keyof BaseQueryNarrowing, 'safely'>>

@mdm317 mdm317 marked this pull request as draft September 14, 2025 08:08
Copy link

nx-cloud bot commented Sep 14, 2025

View your CI Pipeline Execution ↗ for commit 7744947

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-14 16:00:21 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant