MrWolfZ/ngrx-forms

FormControlState should be able to take unknown as generic type

Yohandah opened this issue · 0 comments

Describe the bug
FormControlState<unknown>; throws TS2344: Type 'unknown' does not satisfy the constraint 'FormControlValueTypes'.   Type 'unknown' is not assignable to type 'Boxed<any>'. while any is working. I have a eslint rule that disallow the use of any and I can't see why unknown can't work.

I am in need of this because I have a reusable component that takes a FormControlState as an Input and then use it in the template, it could be a number, a string, ... but I don't care I don't need to know

@Input() formControlState!: FormControlState<unknown>;

<mat-form-field class="field" appearance="outline" floatLabel="always">
  <mat-label>{{ label }}</mat-label>
  <input
    matInput
    required
    placeholder="Sélectionner une date ..."
    autocomplete="off"
    [ngrxFormControlState]="formStateControl"
    [ngrxValueConverter]="dateValueConverter"
    [matDatepicker]="picker"
  />
  <mat-hint>JJ/MM/AAAA</mat-hint>
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>

  <mat-error *ngIf="formStateControl.errors">
    <ng-container *ngIf="formStateControl.errors?.required"> Champ obligatoire.</ng-container>
  </mat-error>
</mat-form-field>