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
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| resource({ | ||
| params, | ||
| loader: async ({params}) => `got: ${params.x}`, | ||
| loader: async ({params}) => `got: ${params!.x}`, |
There was a problem hiding this comment.
This is still not an acceptable solution.
The type shouldn't show up as nullable if the param isn't.
There was a problem hiding this comment.
don't close the PR checking the test cases why it is falling because locally it is working fine.
if you are closing please provide something so that next time i will make sure of that :)
There was a problem hiding this comment.
AS mentionned in the comments in the issue. The problem also exists on resource().
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
please review again now fixed the resource too @JeanMeche
|
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? |
15f8fcc to
6ee7218
Compare
…r#68167) Align resource and rxResource typings with the runtime null sentinel when params are omitted or explicitly 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). |
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