Repository navigation
Closed
Closed
Copy link
Labels
area: coreIssues related to the framework runtimebugcore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: types
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
request field in ResourceLoaderParams should exclude undefined type from returned value of request function.
export class ProductViewer {
productId = input.required<number | undefined>();
productResource: ResourceRef<Product> = resource({
request: () => this.productId(), // <= number | undefined
loader: async ({ request: productId, abortSignal }) => {
assertDefined(productId); // number;
const resp = await fetch(`https://dummyjson.com/products/${productId}`);
return resp.json() as Promise<Product>;
},
});
}export interface ResourceLoaderParams<R> {
request: Exclude<NoInfer<R>, undefined>;
abortSignal: AbortSignal;
previous: {
status: ResourceStatus;
};
}However, undefined is not excluded for certain types. In my experiments, the behavior is observed when the type is not a primitive like string or number, and can be reproduced by simply changing the type number to Number, for example:
export class ProductViewer {
productId = input.required<Number | undefined>();
productResource: ResourceRef<Product> = resource({
request: () => this.productId(), // <= Number | undefined
loader: async ({ request: productId, abortSignal }) => {
assertDefined(productId); // !!! undefined remains !!!
const resp = await fetch(`https://dummyjson.com/products/${productId}`);
return resp.json() as Promise<Product>;
},
});
}This is a typedef issue, as the request parameter cannot be undefined.
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 19.0.0
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64
Angular: 19.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router
Anything else?
No response
Reacted by Samuel Fernández, Dmitry A. Efimenko and bjarketrux
Reacted by daiscog
Metadata
Metadata
Labels
area: coreIssues related to the framework runtimebugcore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: types
Activity
lacolaco commentedon Nov 25, 2024
The
NoInfertype appears to be responsible for the current strange behavior.With the current implementation:
Exclude<NoInfer<R>, undefined>;https://www.typescriptlang.org/play/?#code/C4TwDgpgBAogHgYwDYFcAmECqA7DAzAS2wjQB4AlAPigF5ZFUNSA5AewEls8IAnCygDRQUuCIWJpKAbgBQMpBGBRsARgBc9ZOiyjxJUthQBbAEa8oAH2G6iJanRH5baKVDduA9B6isA1vMVlACYNeC0MHCcJFmMzHktrKLtaRLFnV3coL2VWJQgGbTQApQBndU1GHSSyEuAeIgBzBMc0iXtUvRdMrO8-YqgSkIrtSNb9AGU6xuabNpSWzoz3bOxcqHzwkn60crDK0c7SABEAQ2BoKwXndquJJcyVtY3KooUlE54eXYKI2f1DUy8ADaAF0ZtUbn8uo88j8tm8fCYAFbfTYHZykADeAF9wWNJPMofdlr1-AjDEgkKj9lCDChKXjOpDqvdsn0gA
Without
NoInfer:https://www.typescriptlang.org/play/?#code/C4TwDgpgBAogHgYwDYFcAmECqA7DAzAS2wjQB4AlAPigF5ZFUMKAaKFXCQ4tSgbgCh+SCMCjYAjAC56ydFg5cSpbCgC2AIwgAnKAB82CoiWp12+I2l5Rr1gPS2oAewDWQkWIBM0+LIw5z3KQAcmqaOvpmnBYmBgEkVjZQ9k6uwqIAzlIyjPJxZOnAWkQA5nqxUdwxkYqWiUkOLm4ZXtly-hVKAMqFJWXV0bTlNQk2yY1pUGhZPjntNaQAIgCGwNARhpWD-dwjiWOp7ktaWtMMbRtKKhraANoAun0XPFtPVvtNTuoAVqe+uR1kADeAF9Hnkqq86nYGgdRCokEhfrMnsoUAiwQCIXldu8gA
JeanMeche commentedon Nov 25, 2024
This looks like an upstream issue with Infer, I've filed microsoft/TypeScript#60594 to track it.
samuelfernandez commentedon Nov 26, 2024
In the meantime, would it be possible to temporarily remove the NoInfer to make sure the loader does not have the undefined type? I feel it is hurting more than helping given this issue exists...
DmitryEfimenko commentedon Nov 27, 2024
switching from
Exclude<NoInfer<R>, undefined>toNoInfer<Exclude<R, undefined>>seems to resolve the issuefix(core): correctly infer the `request` type.
refactor(core): rename resource's `request` to `params` (angular#60919)
angular-automatic-lock-bot commentedon May 24, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.