File tree Expand file tree Collapse file tree 3 files changed +41
-2
lines changed
Expand file tree Collapse file tree 3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -556,7 +556,7 @@ export interface FormRecord<TControl> {
556556 emitEvent? : boolean ;
557557 }): void ;
558558 setValue(value : {
559- [key : string ]: ɵ Value <TControl >;
559+ [key : string ]: ɵ RawValue <TControl >;
560560 }, options ? : {
561561 onlySelf? : boolean ;
562562 emitEvent? : boolean ;
Original file line number Diff line number Diff line change @@ -769,7 +769,7 @@ export interface FormRecord<TControl> {
769769 * See `FormGroup#setValue` for additional information.
770770 */
771771 setValue (
772- value : { [ key : string ] : ɵValue < TControl > } ,
772+ value : { [ key : string ] : ɵRawValue < TControl > } ,
773773 options ?: {
774774 onlySelf ?: boolean ;
775775 emitEvent ?: boolean ;
Original file line number Diff line number Diff line change 99// These tests mainly check the types of strongly typed form controls, which is generally enforced
1010// at compile time.
1111
12+ import { ɵRawValue } from '@angular/forms' ;
1213import { FormBuilder , NonNullableFormBuilder , UntypedFormBuilder } from '../src/form_builder' ;
1314import {
1415 AbstractControl ,
@@ -728,6 +729,44 @@ describe('Typed Class', () => {
728729 c . reset ( { c : 42 , d : 0 } ) ;
729730 c . removeControl ( 'c' ) ;
730731 } ) ;
732+
733+ it ( 'should only accept non-partial values' , ( ) => {
734+ const fr = new FormRecord < FormGroup < { foo : FormControl < number > ; bar : FormControl < number > } > > ( {
735+ group1 : new FormGroup ( {
736+ foo : new FormControl ( 42 , { nonNullable : true } ) ,
737+ bar : new FormControl ( 42 , { nonNullable : true } ) ,
738+ } ) ,
739+ } ) ;
740+
741+ type ValueParam = Parameters < typeof fr . setValue > [ 0 ] ;
742+
743+ // This should error if the typing allows partial values
744+ const value : ValueParam = {
745+ // @ts -expect-error
746+ group1 : {
747+ foo : 42 ,
748+ // bar value is missing
749+ } ,
750+ } ;
751+
752+ type RecordRawValue = ɵRawValue < typeof fr > ;
753+ const rawValue : RecordRawValue = {
754+ // @ts -expect-error
755+ group1 : {
756+ foo : 42 ,
757+ // bar value is missing
758+ } ,
759+ } ;
760+
761+ expect ( ( ) =>
762+ fr . setValue ( {
763+ // @ts -expect-error
764+ group1 : {
765+ foo : 42 ,
766+ } ,
767+ } ) ,
768+ ) . 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 / ) ;
769+ } ) ;
731770 } ) ;
732771
733772 describe ( 'FormArray' , ( ) => {
You can’t perform that action at this time.
0 commit comments