You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works through most generic types and classes as well (eg. a Promise<typeof value> can be used in place of a Promise<typeof subset>).
However, this doesn't work (most of the time) when assigning across FormGroups. This would be a useful feature for shareable/generic form components - they could take a FormGroup of a certain type, where some (or all) fields might be optional, but where the passing component can specify some of them.
The error (specifically in the second example) suggests the type is forcing the assignability check in both directions regardless of which side is actually being assigned, while the two types are at least somewhat compatible (can be compared).
The only alternative at the moment is to use the least restrictive type for everything, which can add unneeded fields to the usages, and/or add unneeded and cumbersome optionality/nullability.
Wasn't sure whether to put this as a feature request or bug, since there might actually be a functional difference/design decision that I'm not understanding. Possibly (?) related to #47091 but that seemed a bit more specific and had some inheritence/extension complexity.
T being on the right hand of 0 extends(1&T) means all assignability checks have to go both ways. I can't reason about this well enough to tell if it's strange or not. lol.
I guess this means this is blocked on improved support TypeScript-side for any detection, or on removing IsAny? At a glance, it looks like it might be possible to keep the external types (mostly?) the same without conditional types, though I guess it might be difficult to replicate the extent of the any-ness in its current form.
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
In TS you can take advantage of duck typing to assign objects that contain the full shape of another, for example:
This works through most generic types and classes as well (eg. a
Promise<typeof value>
can be used in place of aPromise<typeof subset>
).However, this doesn't work (most of the time) when assigning across
FormGroup
s. This would be a useful feature for shareable/generic form components - they could take aFormGroup
of a certain type, where some (or all) fields might be optional, but where the passing component can specify some of them.Some examples are in this stackblitz: https://stackblitz.com/edit/angular-jgpu5s?file=src/main.ts
The error (specifically in the second example) suggests the type is forcing the assignability check in both directions regardless of which side is actually being assigned, while the two types are at least somewhat compatible (can be compared).
The only alternative at the moment is to use the least restrictive type for everything, which can add unneeded fields to the usages, and/or add unneeded and cumbersome optionality/nullability.
Wasn't sure whether to put this as a feature request or bug, since there might actually be a functional difference/design decision that I'm not understanding. Possibly (?) related to #47091 but that seemed a bit more specific and had some inheritence/extension complexity.
Proposed solution
Support this:
or at least this:
Alternatives considered
N/A?
The text was updated successfully, but these errors were encountered: