iamguid / ngx-mf

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

String Property with name 'link' is typed as never #5

Closed ebiermann closed 1 year ago

ebiermann commented 1 year ago

If one of the properties in your model is called "link" it will be typed as never instead of its actual type (for example string). Here is an isolated test that will show a type error when trying to create a FormGroup for BrokenForm:


  it('linkTest', () => {
    interface Working {
      name: string;
    }
    interface Broken {
      link: string;
    }

    type WorkingForm = FormModel<Working>;
    type BrokenForm = FormModel<Broken>;

    const wf = new FormGroup<WorkingForm['controls']>({name: new FormControl('Name')}); // works fine
    const bf = new FormGroup<BrokenForm['controls']>({link: new FormControl('Link')});  // Type 'FormControl<string | null>' is not assignable to type 'never' 
  });`
iamguid commented 1 year ago

Thanks for the issue, I'll check today

wwaters-ms commented 1 year ago

Same with a property named search.

type FormValues = FormModel<{ search: string; searchType: string; }>; Calling it search1 works, but search wants to be type never. I just tried upgrading from 1.4.10 to 3.0.0 when the error started appearing.

iamguid commented 1 year ago

Ok, I'll check it in current weekends, sorry, I was busy

iamguid commented 1 year ago

So, problem cause by String definitions global type https://github.com/microsoft/TypeScript/blob/e9868e96e87996df46a13b4323866acc639e71ce/src/lib/es2015.core.d.ts#L380