fix(core): derive possible null value in rxResource stream params (#6…#68171
fix(core): derive possible null value in rxResource stream params (#6…#68171surajy93 wants to merge 1 commit intoangular:mainfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
It looks better. |
let me check and test it please provide all the test cases and details thank you |
|
Also please check the CLA check. You're authoring your commits with 2 different names. |
loader should stay typed as string here, not string | undefined. When a params function is provided, Angular treats undefined as “no request” and leaves the resource idle, so the loader is not invoked for that branch. In other words, params() may return string | undefined, but loader only runs for the resolved, non-undefined case. The nullable case we’re fixing is different: it applies when the params option itself is omitted or explicitly undefined, because Angular uses an internal null sentinel there.` Shorter version: I don’t think this one should widen to \string | undefined please comment or suggestion why do u think that it should be string |undefined? |
6ee7218 to
df0e61a
Compare
|
@JeanMeche apart the this edge cases everything look fine can you please take a look |
|
Yeah you're right, my bad for that bad example. Something else. In your test you have: which should arguably have a single generic (since the request is not defined). |
This comment was marked as outdated.
This comment was marked as outdated.
afd1329 to
d4e5368
Compare
98c8099 to
7560a7e
Compare
7560a7e to
4b58de4
Compare
There was a problem hiding this comment.
I have fix the test failed can you please again rerun the pipeline @JeanMeche
|
I would also expect test that show that the typings are correct here. |
1370f6e to
e314c24
Compare
surajy93
left a comment
There was a problem hiding this comment.
@JeanMeche i have cover all the test cases and revert the run time code as mention ,
example below :
//params ommitted
resource1 = resource({
loader: async ({params}) => {
console.log(params); // {} | null | undefined
return 'hello';
}
})
paramsSignal = signal<Params | undefined>(undefined);
// params are optional
resource2 = resource({
params: this.getParams(),
loader: async ({params}) => {
console.log(params); // string | undefined
return 'hello';
}
})
resource3 = rxResource({
params: this.getParams(),
stream: ({params}) => {
console.log(params); // string | undefined
return of(params ? id=${params} : 'no id');
}
})
resource4 = resource({
params: () => 'test',
loader: async ({params}) => {
console.log(params) // string
return 'hello'
}
})
resource5 = resource({
params: () => 0,
loader: async ({params}) => {
console.log(params) // number
return 'hello'
}
})
resource6 =rxResource({
params: () => 'test',
stream: ({params}) => {
console.log(params) // string
return of('hello')
}
})
resource7 = rxResource({
params: () => 0,
stream: ({params}) => {
console.log(params) // number
return of('hello')
}
})
getParams(): (() => string) | undefined {
return Math.random() > 0.5 ? () => 'test' : undefined;
}
please review again and provide the feedback :)
surajy93
left a comment
There was a problem hiding this comment.
I have resolve the comment issue mention @JeanMeche please review again
| * | ||
| * @experimental 19.0 | ||
| * @see [Async reactivity with resources](guide/signals/resource) | ||
| */ |
There was a problem hiding this comment.
I don't think we should delete the tsDocs file we have (similar to another one we have above)
900fe3c to
b8f4436
Compare
|
I have squashed & pushed something that is simpler and more correct. PTAL and let me know what you think :) |
b8f4436 to
477c9fa
Compare
477c9fa to
4076690
Compare
When the params is undefined or returns undefined, the param of the loader/stream gets the type `never`. fixes angular#68167
4076690 to
b8d5269
Compare
yes, it looks good, tested and working fine and sorry next time i will do better and thanks you for your patience and review :) |
When an optional params function returns
undefined, Angular'srxResourceinternally defaults the params loader value tonullat runtime. This change updatesResourceLoaderParams<R>to correctly allownullalongside the resolved type, ensuring developers get accurate TypeScript feedback when omitted.Fixes #62724
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When the
paramsoption is not provided torxResourceor it evaluates toundefined, the type of theparamsargument in the internalstreamfunction is restricted to the strictly inferred type (e.g.Params), even though it resolves tonullat runtime.Issue Number: #62724
What is the new behavior?
The type inference for
ResourceLoaderParams<R>correctly derives a potentialnullvalue in instances whereundefinedcould be inferred from the originalparamsoption payload. This correctly aligns the TypeScript expectations withinstreamorloaderfunctions to match the runtime behavior.Does this PR introduce a breaking change?
Other information
N/A