Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
Currently validateAsync resource factory expects a ResourceRef. At runtime, it works with the base Resource interface. The only thing outside the Resource interface that it handles is ResourceRef reloading, but that has optional chaining for objects that do not have the .reloadmethod.
|
const keys = this.logicNode.logic.getMetadataKeys(); |
|
for (const key of keys) { |
|
if (key[IS_ASYNC_VALIDATION_RESOURCE]) { |
|
const resource = this.metadata(key)! as Resource<unknown> & |
|
Partial<Pick<WritableResource<unknown>, 'reload'>>; |
|
resource.reload?.(); |
|
} |
|
} |
|
|
Proposed solution
Change the factory type to accept a Resource interface instead of the larger ResourceRef interface.
This would make it easier for external libraries to work with async validation.
Alternatives considered
A new interface that extends Resource and adds only the reload method. WritableResource could extend that interface.
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
Currently validateAsync resource factory expects a
ResourceRef. At runtime, it works with the baseResourceinterface. The only thing outside the Resource interface that it handles isResourceRefreloading, but that has optional chaining for objects that do not have the.reloadmethod.angular/packages/forms/signals/src/field/node.ts
Lines 364 to 372 in 302dd0f
Proposed solution
Change the
factorytype to accept aResourceinterface instead of the largerResourceRefinterface.This would make it easier for external libraries to work with async validation.
Alternatives considered
A new interface that extends
Resourceand adds only thereloadmethod.WritableResourcecould extend that interface.