@@ -158,6 +158,17 @@ describe('Typed Class', () => {
158158 let ufc : UntypedFormControl ;
159159 ufc = c ;
160160 } ) ;
161+
162+ it ( 'should infer value type correctly' , ( ) => {
163+ function valueFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
164+ return ctrl . value ;
165+ }
166+
167+ const c = new FormControl < { foo : string } > ( { foo : '' } ) ;
168+ let val : { foo : string } | null ;
169+ val = valueFn ( c ) ;
170+ val = valueFn ( c ) ! ;
171+ } ) ;
161172 } ) ;
162173
163174 describe ( 'FormGroup' , ( ) => {
@@ -676,6 +687,39 @@ describe('Typed Class', () => {
676687 } ) ;
677688 ufg = fg ;
678689 } ) ;
690+
691+ it ( 'should support ControlState as reset argument' , ( ) => {
692+ const fg = new FormGroup ( {
693+ name : new FormControl ( { foo : 'foo' } ) ,
694+ } ) ;
695+ fg . reset ( { name : { foo : 'bar' } } ) ;
696+
697+ fg . reset ( { name : { value : { foo : 'bar' } , disabled : true } } ) ;
698+ } ) ;
699+
700+ it ( 'should infer value type correctly' , ( ) => {
701+ function valueFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
702+ return ctrl . value ;
703+ }
704+ const fg = new FormGroup ( {
705+ name : new FormControl ( 'bob' ) ,
706+ } ) ;
707+
708+ let val : Partial < { name : string | null } > ;
709+ val = valueFn ( fg ) ;
710+ } ) ;
711+
712+ it ( 'should reset inferred formGroup' , ( ) => {
713+ function ctrlFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
714+ return ctrl ;
715+ }
716+
717+ const fg = new FormGroup ( {
718+ name : new FormControl ( 'bob' ) ,
719+ } ) ;
720+ ctrlFn ( fg ) . reset ( { name : 'matt' } ) ;
721+ ctrlFn ( fg ) . reset ( { name : { value : 'matt' , disabled : true } } ) ;
722+ } ) ;
679723 } ) ;
680724
681725 describe ( 'FormRecord' , ( ) => {
@@ -767,6 +811,16 @@ describe('Typed Class', () => {
767811 } ) ,
768812 ) . toThrowError ( / N G 0 1 0 0 2 : M u s t s u p p l y a v a l u e f o r f o r m c o n t r o l / ) ;
769813 } ) ;
814+
815+ it ( 'should reset inferred formarray' , ( ) => {
816+ function ctrlFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
817+ return ctrl ;
818+ }
819+
820+ let c = new FormRecord < FormControl < number > > ( { a : new FormControl ( 42 , { nonNullable : true } ) } ) ;
821+ ctrlFn ( c ) . reset ( { a : 99 } ) ;
822+ ctrlFn ( c ) . reset ( { a : { value : 99 , disabled : true } } ) ;
823+ } ) ;
770824 } ) ;
771825
772826 describe ( 'FormArray' , ( ) => {
@@ -942,6 +996,25 @@ describe('Typed Class', () => {
942996 const fa = new FormArray ( [ new FormControl ( 'bob' ) ] ) ;
943997 ufa = fa ;
944998 } ) ;
999+
1000+ it ( 'should infer value type correctly' , ( ) => {
1001+ function valueFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
1002+ return ctrl . value ;
1003+ }
1004+
1005+ const fa = new FormArray ( [ new FormControl ( 'bob' ) ] ) ;
1006+ let val : ( string | null ) [ ] ;
1007+ val = valueFn ( fa ) ;
1008+ } ) ;
1009+
1010+ it ( 'should reset inferred formarray' , ( ) => {
1011+ function ctrlFn < T , U extends T , V > ( ctrl : AbstractControl < T , U , V > ) {
1012+ return ctrl ;
1013+ }
1014+
1015+ const fa = new FormArray ( [ new FormControl ( 'bob' ) ] ) ;
1016+ ctrlFn ( fa ) . reset ( [ 'jim' , 'jam' , 'joe' ] ) ;
1017+ } ) ;
9451018 } ) ;
9461019
9471020 it ( 'model classes support a complex, deeply nested case' , ( ) => {
0 commit comments