Tinkoff / tui-ngrx-forms-adapter

Apache License 2.0
6 stars 0 forks source link

[BUG] Allow undefined for a FormControlState #2

Closed Yohandah closed 1 year ago

Yohandah commented 2 years ago

šŸž Bug report

Description

The directive should allow for FormControlState<string | undefined>

Reproduction

const initialFormState: FormGroupState = createFormGroupState( 'myForm', { myProp: undefined, } )

* Add the field to your template with the directive

<form *ngIf="myForm$ | async as myForm" [ngrxFormState]="myForm"> <tui-select [ngrxFormControlState]="myForm.controls.myProp">

  <tui-data-list-wrapper
    tuiDataList
    [items]="['1', '2', '3']"
    ></tui-data-list-wrapper>


Throwing error 

error TS2322: Type 'FormControlState<string | undefined> | undefined' is not assignable to type 'AbstractControlState'.
Type 'undefined' is not assignable to type 'AbstractControlState'.

22 [ngrxFormControlState]="myForm.controls.project"



### Expected behavior
It should allow `undefined`, to make it work I have to do the following `[ngrxFormControlState]="myForm.controls.project!"` with `!` but it's not ideal
Yohandah commented 2 years ago

@makar-l @waterplea I ping you because I'm not sure you keep an eye on this library. Is it still supported ?

makar-l commented 1 year ago

Hello Yohandah! Sorry for leaving you without attention. I will fix it, thank you

makar-l commented 1 year ago

Hello @Yohandah

I've checked your case. This error is form ngrx-forms itself, not from the adapter.

But for me it looks logical, that undefined control state is an invalid case. If you are using the "!", I guess, it's invalid for your case too. So I think you need to correct your types or check nullable via "ngIf".

Thank you for paying attention to my small lib. Wish you a good day :)