-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(angular-query): fix injectInfiniteQuery to narrow type #9653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
Pre-merge checks✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this 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 nitsMissing 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 initialDataThe three cases correctly validate narrowing behavior: data undefined on
isPending
, data defined onisSuccess
, and error defined onisError
.Consider adding one negative assertion outside guards to ensure
data()
isInfiniteData<string, unknown> | undefined
by default (no initialData).
79-141
: Excellent: with initialData, pending still yields defined dataThese tests capture the critical regression vector:
isPending
should still expose defineddata()
wheninitialData
is present. The addedisSuccess
/isError
checks round it out nicely.Optionally assert that
data()
remains defined in theisError
branch withinitialData
, mirroring runtime behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.
> =BaseQueryNarrowing<TData, TError> & | ||
MapToSignals<TDefinedInfiniteQueryObserver> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
> =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'>> |
View your CI Pipeline Execution ↗ for commit 7744947
☁️ Nx Cloud last updated this comment at |
fixes: #9016
isSuccess
,isPending
,isError
with initial dataisPending
,isError
when initial data is not providedSummary by CodeRabbit
New Features
Tests