@@ -51,15 +51,17 @@ class ControlValueAccessorAdapter implements FormViewAdapter {
5151 }
5252}
5353
54+ export type NgrxFormControlValueType < TStateValue > = TStateValue extends FormControlValueTypes ? TStateValue : never ;
55+
5456@Directive ( {
5557 // tslint:disable-next-line:directive-selector
5658 selector : ':not([ngrxFormsAction])[ngrxFormControlState]' ,
5759} )
58- export class NgrxFormControlDirective < TStateValue extends FormControlValueTypes , TViewValue = TStateValue > implements AfterViewInit , OnInit {
60+ export class NgrxFormControlDirective < TStateValue , TViewValue = TStateValue > implements AfterViewInit , OnInit {
5961 private isInitialized = false ;
6062 private focusTrackingIsEnabled = false ;
6163
62- @Input ( ) set ngrxFormControlState ( newState : FormControlState < TStateValue > ) {
64+ @Input ( ) set ngrxFormControlState ( newState : FormControlState < NgrxFormControlValueType < TStateValue > > ) {
6365 if ( ! newState ) {
6466 throw new Error ( 'The control state must not be undefined!' ) ;
6567 }
@@ -92,7 +94,7 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
9294 return this . state && this . state . isFocused ? '' : null ;
9395 }
9496
95- state : FormControlState < TStateValue > ;
97+ state : FormControlState < NgrxFormControlValueType < TStateValue > > ;
9698
9799 private viewAdapter : FormViewAdapter ;
98100
@@ -128,7 +130,10 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
128130 : selectViewAdapter ( viewAdapters ) ;
129131 }
130132
131- updateViewIfControlIdChanged ( newState : FormControlState < TStateValue > , oldState : FormControlState < TStateValue > | undefined ) {
133+ updateViewIfControlIdChanged (
134+ newState : FormControlState < NgrxFormControlValueType < TStateValue > > ,
135+ oldState : FormControlState < NgrxFormControlValueType < TStateValue > > | undefined ,
136+ ) {
132137 if ( oldState && newState . id === oldState . id ) {
133138 return ;
134139 }
@@ -141,7 +146,10 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
141146 }
142147 }
143148
144- updateViewIfValueChanged ( newState : FormControlState < TStateValue > , _ : FormControlState < TStateValue > | undefined ) {
149+ updateViewIfValueChanged (
150+ newState : FormControlState < NgrxFormControlValueType < TStateValue > > ,
151+ _ : FormControlState < NgrxFormControlValueType < TStateValue > > | undefined ,
152+ ) {
145153 if ( newState . value === this . stateValue ) {
146154 return ;
147155 }
@@ -151,7 +159,10 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
151159 this . viewAdapter . setViewValue ( this . viewValue ) ;
152160 }
153161
154- updateViewIfIsDisabledChanged ( newState : FormControlState < TStateValue > , oldState : FormControlState < TStateValue > | undefined ) {
162+ updateViewIfIsDisabledChanged (
163+ newState : FormControlState < NgrxFormControlValueType < TStateValue > > ,
164+ oldState : FormControlState < NgrxFormControlValueType < TStateValue > > | undefined ,
165+ ) {
155166 if ( ! this . viewAdapter . setIsDisabled ) {
156167 return ;
157168 }
@@ -163,7 +174,10 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
163174 this . viewAdapter . setIsDisabled ( newState . isDisabled ) ;
164175 }
165176
166- updateViewIfIsFocusedChanged ( newState : FormControlState < TStateValue > , oldState : FormControlState < TStateValue > | undefined ) {
177+ updateViewIfIsFocusedChanged (
178+ newState : FormControlState < NgrxFormControlValueType < TStateValue > > ,
179+ oldState : FormControlState < NgrxFormControlValueType < TStateValue > > | undefined ,
180+ ) {
167181 if ( ! this . focusTrackingIsEnabled ) {
168182 return ;
169183 }
@@ -179,7 +193,7 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
179193 }
180194 }
181195
182- protected dispatchAction ( action : Actions < TStateValue > ) {
196+ protected dispatchAction ( action : Actions < NgrxFormControlValueType < TStateValue > > ) {
183197 if ( this . actionsSubject !== null ) {
184198 this . actionsSubject . next ( action ) ;
185199 } else {
@@ -208,7 +222,7 @@ export class NgrxFormControlDirective<TStateValue extends FormControlValueTypes,
208222 const dispatchSetValueAction = ( ) => {
209223 this . stateValue = this . ngrxValueConverter . convertViewToStateValue ( this . viewValue ) ;
210224 if ( this . stateValue !== this . state . value ) {
211- this . dispatchAction ( new SetValueAction ( this . state . id , this . stateValue ) ) ;
225+ this . dispatchAction ( new SetValueAction ( this . state . id , this . stateValue as NgrxFormControlValueType < TStateValue > ) ) ;
212226
213227 dispatchMarkAsDirtyAction ( ) ;
214228 }
0 commit comments