From 5fd2c8f2d6f3ff4abe9d3d3976338d2bfcd35002 Mon Sep 17 00:00:00 2001 From: danranVm Date: Sat, 25 Apr 2020 11:42:18 +0800 Subject: [PATCH] refactor(forms): remove unnecessary `!` operators from validators (#36805) When we added the strict null checks, the lexer had some `!` operators added to prevent the compilation from failing. See #24571 PR Close #36805 --- packages/forms/src/directives/validators.ts | 42 ++++++++------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/forms/src/directives/validators.ts b/packages/forms/src/directives/validators.ts index f7b38fcf1f..16b9183486 100644 --- a/packages/forms/src/directives/validators.ts +++ b/packages/forms/src/directives/validators.ts @@ -158,10 +158,8 @@ export const CHECKBOX_REQUIRED_VALIDATOR: StaticProvider = { host: {'[attr.required]': 'required ? "" : null'} }) export class RequiredValidator implements Validator { - // TODO(issue/24571): remove '!'. - private _required!: boolean; - // TODO(issue/24571): remove '!'. - private _onChange!: () => void; + private _required = false; + private _onChange?: () => void; /** * @description @@ -274,10 +272,8 @@ export const EMAIL_VALIDATOR: any = { providers: [EMAIL_VALIDATOR] }) export class EmailValidator implements Validator { - // TODO(issue/24571): remove '!'. - private _enabled!: boolean; - // TODO(issue/24571): remove '!'. - private _onChange!: () => void; + private _enabled = false; + private _onChange?: () => void; /** * @description @@ -368,17 +364,15 @@ export const MIN_LENGTH_VALIDATOR: any = { host: {'[attr.minlength]': 'minlength ? minlength : null'} }) export class MinLengthValidator implements Validator, OnChanges { - // TODO(issue/24571): remove '!'. - private _validator!: ValidatorFn; - // TODO(issue/24571): remove '!'. - private _onChange!: () => void; + private _validator: ValidatorFn = Validators.nullValidator; + private _onChange?: () => void; /** * @description * Tracks changes to the the minimum length bound to this directive. */ - // TODO(issue/24571): remove '!'. - @Input() minlength!: string|number; + @Input() + minlength!: string|number; // This input is always defined, since the name matches selector. /** * @description @@ -456,17 +450,15 @@ export const MAX_LENGTH_VALIDATOR: any = { host: {'[attr.maxlength]': 'maxlength ? maxlength : null'} }) export class MaxLengthValidator implements Validator, OnChanges { - // TODO(issue/24571): remove '!'. - private _validator!: ValidatorFn; - // TODO(issue/24571): remove '!'. - private _onChange!: () => void; + private _validator: ValidatorFn = Validators.nullValidator; + private _onChange?: () => void; /** * @description * Tracks changes to the the maximum length bound to this directive. */ - // TODO(issue/24571): remove '!'. - @Input() maxlength!: string|number; + @Input() + maxlength!: string|number; // This input is always defined, since the name matches selector. /** * @description @@ -547,17 +539,15 @@ export const PATTERN_VALIDATOR: any = { host: {'[attr.pattern]': 'pattern ? pattern : null'} }) export class PatternValidator implements Validator, OnChanges { - // TODO(issue/24571): remove '!'. - private _validator!: ValidatorFn; - // TODO(issue/24571): remove '!'. - private _onChange!: () => void; + private _validator: ValidatorFn = Validators.nullValidator; + private _onChange?: () => void; /** * @description * Tracks changes to the pattern bound to this directive. */ - // TODO(issue/24571): remove '!'. - @Input() pattern!: string|RegExp; + @Input() + pattern!: string|RegExp; // This input is always defined, since the name matches selector. /** * @description