remapFromFormGroup
shouldn't allow extra props to be returned
#162
Labels
effort-1: minutes
Will only take a few minutes to fix/create
flag: breaking change
This feature or fix will require a breaking change
scope: lib
Anything related to the library itself
type: feature
This is a new feature
When creating a sub form we are strict and expect no missing properties, nor additional ones.
This lets us behind the scenes use
setValue
instead ofpatchValue
which wouldn't be really safe as we could end up patching something completely unrelated to form without noticing.When using the remap functionality, we say that:
ControlInterface
should be transformed into an "internal" value that is of typeFormInterface
ControlInterface
as well, driven by the current form value (of typeFormInterface
)The issue is the following: TypeScript uses structural typing instead of nominal typing which means that extra properties are not an issue. So when the form has some internal state, for example the current value of a select when working with polymorphic forms, it's totally fine to just return the form value. Even though it contains and additional key/value.
Coming from a form, this could easily lead to runtime issues as the server could perform checks and make sure that no extra properties are here, etc.
We might as well be strict and enforce this ourselves by doing a little trick.
The text was updated successfully, but these errors were encountered: