Repository navigation
Conversation
Non-blocking route resources are bound to component inputs as the router-wrapped resource, which supports `reload()` but not `set()` or `update()`. There was no public named type for it, so users had to declare their own intersection type to receive it as an input. Add `RouteResource<T>` and use it for `ResourceResult` and the return type of the internal `routerResource()`. Fixes angular#71299
Update the route resources guide to type non-blocking resource inputs with `RouteResource` and mention the type exposed by the router.
|
I don鈥檛 feel like Router should own a type for this, which is why one wasn't exposed here. |
|
@atscott Thanks for the context. I understand the hesitation about the router owning this type, and I'm open to where it should live. From actually using route resources, though, I've found a public type for this model to be necessary in practice, and not only for typing private readonly users = inject(ActivatedRoute).resources?.['users'] as
(Resource<User[]> & { reload(): boolean }) | undefined;So whether the resource reaches the component through an input or through Since this isn't really router-specific, I agree it would fit better in |
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?
A
nonBlocking()route resource is bound to a component input as the router-wrapped resource, which supportsreload()but notset()orupdate(). There is no public type for it:Resource<T>has noreload(), andWritableResource<T>/ResourceRef<T>declare methods the router-wrapped resource does not implement. Users have to declare their ownResource<T> & {reload(): boolean}to type the input. #70702 gaveActivatedRoute.resourcesareload()through an anonymous intersection inResourceResult, which cannot be reused for component inputs.Issue Number: #71299
What is the new behavior?
RouteResource<T>is exported from@angular/routerand used as the value type ofResourceResult, so a non-blocking resource input can be declared asinput.required<RouteResource<T>>()andreload()can be called on it without a cast. The data fetching guide uses this type in the non-blocking example.The name follows the "route resources" terminology of the routing guide and
Route.resources.Does this PR introduce a breaking change?
Other information
This keeps the type in
@angular/router. A framework-wideReloadableResource<T>in@angular/core, mentioned in the #70702 review, is left out of this PR.