@@ -372,15 +372,15 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
372372 *
373373 * @internal
374374 */
375- private _composedValidatorFn : ValidatorFn | null ;
375+ private _composedValidatorFn ! : ValidatorFn | null ;
376376
377377 /**
378378 * Contains the result of merging asynchronous validators into a single validator function
379379 * (combined using `Validators.composeAsync`).
380380 *
381381 * @internal
382382 */
383- private _composedAsyncValidatorFn : AsyncValidatorFn | null ;
383+ private _composedAsyncValidatorFn ! : AsyncValidatorFn | null ;
384384
385385 /**
386386 * Synchronous validators as they were provided:
@@ -390,7 +390,7 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
390390 *
391391 * @internal
392392 */
393- private _rawValidators : ValidatorFn | ValidatorFn [ ] | null ;
393+ private _rawValidators ! : ValidatorFn | ValidatorFn [ ] | null ;
394394
395395 /**
396396 * Asynchronous validators as they were provided:
@@ -401,7 +401,7 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
401401 *
402402 * @internal
403403 */
404- private _rawAsyncValidators : AsyncValidatorFn | AsyncValidatorFn [ ] | null ;
404+ private _rawAsyncValidators ! : AsyncValidatorFn | AsyncValidatorFn [ ] | null ;
405405
406406 /**
407407 * The current value of the control.
@@ -427,10 +427,8 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
427427 constructor (
428428 validators : ValidatorFn | ValidatorFn [ ] | null ,
429429 asyncValidators : AsyncValidatorFn | AsyncValidatorFn [ ] | null ) {
430- this . _rawValidators = validators ;
431- this . _rawAsyncValidators = asyncValidators ;
432- this . _composedValidatorFn = coerceToValidator ( this . _rawValidators ) ;
433- this . _composedAsyncValidatorFn = coerceToAsyncValidator ( this . _rawAsyncValidators ) ;
430+ this . _assignValidators ( validators ) ;
431+ this . _assignAsyncValidators ( asyncValidators ) ;
434432 }
435433
436434 /**
@@ -620,8 +618,7 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
620618 * using `addValidators()` method instead.
621619 */
622620 setValidators ( validators : ValidatorFn | ValidatorFn [ ] | null ) : void {
623- this . _rawValidators = validators ;
624- this . _composedValidatorFn = coerceToValidator ( validators ) ;
621+ this . _assignValidators ( validators ) ;
625622 }
626623
627624 /**
@@ -635,8 +632,7 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
635632 * using `addAsyncValidators()` method instead.
636633 */
637634 setAsyncValidators ( validators : AsyncValidatorFn | AsyncValidatorFn [ ] | null ) : void {
638- this . _rawAsyncValidators = validators ;
639- this . _composedAsyncValidatorFn = coerceToAsyncValidator ( validators ) ;
635+ this . _assignAsyncValidators ( validators ) ;
640636 }
641637
642638 /**
@@ -1377,4 +1373,24 @@ export abstract class AbstractControl<TValue = any, TRawValue extends TValue = T
13771373 _find ( name : string | number ) : AbstractControl | null {
13781374 return null ;
13791375 }
1376+
1377+ /**
1378+ * Internal implementation of the `setValidators` method. Needs to be separated out into a
1379+ * different method, because it is called in the constructor and it can break cases where
1380+ * a control is extended.
1381+ */
1382+ private _assignValidators ( validators : ValidatorFn | ValidatorFn [ ] | null ) : void {
1383+ this . _rawValidators = Array . isArray ( validators ) ? validators . slice ( ) : validators ;
1384+ this . _composedValidatorFn = coerceToValidator ( this . _rawValidators ) ;
1385+ }
1386+
1387+ /**
1388+ * Internal implementation of the `setAsyncValidators` method. Needs to be separated out into a
1389+ * different method, because it is called in the constructor and it can break cases where
1390+ * a control is extended.
1391+ */
1392+ private _assignAsyncValidators ( validators : AsyncValidatorFn | AsyncValidatorFn [ ] | null ) : void {
1393+ this . _rawAsyncValidators = Array . isArray ( validators ) ? validators . slice ( ) : validators ;
1394+ this . _composedAsyncValidatorFn = coerceToAsyncValidator ( this . _rawAsyncValidators ) ;
1395+ }
13801396}
0 commit comments