iamguid / ngx-mf

Bind your model types to angular FormGroup type
MIT License
39 stars 2 forks source link

Create the FormGroup via the spread operator #13

Open iamcoderUA opened 2 months ago

iamcoderUA commented 2 months ago

🚀 Question / feature request

Description

Current behavior: As soon as you try to create a simple form via the spread operator, you gonna receive an error, e.g.

interface Person {
  firstName: string;
  lastName: string;
}

type SimpleForm = FormModel<Person>;

const person = {
  firstName: 'John';
  lastName: 'Smith';
}

const simpleForm = new FormGroup<SimpleForm['controls]>({ ...person })

Error:
Argument of type '{ firstName: string; lastName: string; }' is not assignable to parameter of type 'FormModelKeyofTraverse<Person, FormElementGroup, PrepareModel<Person>>'.
Types of property 'firstName' are incompatible.
Type 'string' is not assignable to type 'FormControl<string>'.

Describe the solution you'd like

I understand that's not a problem of the library, but maybe you have any thoughts how to improve the current behavior? It would be great to have such an improvement, especially within simple forms, where all controls are just a FormControl.

thx in advance :)

iamguid commented 1 month ago

Hello! Thank you for your feedback. Ok I'll check on this weekends.

iamguid commented 1 month ago

@iamcoderUA could you please provide me more context, like what do you want in result? Because as I see spread operator doesn't work because you use string instead of FormControl<string> and it is expected behavior. What do you want to show me with this example? You want to put default values for FormControls or something else?