Skip to content

Commit 396033d

Browse files
danranVmatscott
authored andcommitted
refactor(forms): remove unnecessary ! operators from validators (angular#36805)
When we added the strict null checks, the lexer had some `!` operators added to prevent the compilation from failing. See angular#24571 PR Close angular#36805
1 parent 02ee9d2 commit 396033d

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

packages/forms/src/directives/validators.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,8 @@ export const CHECKBOX_REQUIRED_VALIDATOR: StaticProvider = {
158158
host: {'[attr.required]': 'required ? "" : null'}
159159
})
160160
export class RequiredValidator implements Validator {
161-
// TODO(issue/24571): remove '!'.
162-
private _required!: boolean;
163-
// TODO(issue/24571): remove '!'.
164-
private _onChange!: () => void;
161+
private _required = false;
162+
private _onChange?: () => void;
165163

166164
/**
167165
* @description
@@ -274,10 +272,8 @@ export const EMAIL_VALIDATOR: any = {
274272
providers: [EMAIL_VALIDATOR]
275273
})
276274
export class EmailValidator implements Validator {
277-
// TODO(issue/24571): remove '!'.
278-
private _enabled!: boolean;
279-
// TODO(issue/24571): remove '!'.
280-
private _onChange!: () => void;
275+
private _enabled = false;
276+
private _onChange?: () => void;
281277

282278
/**
283279
* @description
@@ -368,17 +364,15 @@ export const MIN_LENGTH_VALIDATOR: any = {
368364
host: {'[attr.minlength]': 'minlength ? minlength : null'}
369365
})
370366
export class MinLengthValidator implements Validator, OnChanges {
371-
// TODO(issue/24571): remove '!'.
372-
private _validator!: ValidatorFn;
373-
// TODO(issue/24571): remove '!'.
374-
private _onChange!: () => void;
367+
private _validator: ValidatorFn = Validators.nullValidator;
368+
private _onChange?: () => void;
375369

376370
/**
377371
* @description
378372
* Tracks changes to the the minimum length bound to this directive.
379373
*/
380-
// TODO(issue/24571): remove '!'.
381-
@Input() minlength!: string|number;
374+
@Input()
375+
minlength!: string|number; // This input is always defined, since the name matches selector.
382376

383377
/**
384378
* @description
@@ -456,17 +450,15 @@ export const MAX_LENGTH_VALIDATOR: any = {
456450
host: {'[attr.maxlength]': 'maxlength ? maxlength : null'}
457451
})
458452
export class MaxLengthValidator implements Validator, OnChanges {
459-
// TODO(issue/24571): remove '!'.
460-
private _validator!: ValidatorFn;
461-
// TODO(issue/24571): remove '!'.
462-
private _onChange!: () => void;
453+
private _validator: ValidatorFn = Validators.nullValidator;
454+
private _onChange?: () => void;
463455

464456
/**
465457
* @description
466458
* Tracks changes to the the maximum length bound to this directive.
467459
*/
468-
// TODO(issue/24571): remove '!'.
469-
@Input() maxlength!: string|number;
460+
@Input()
461+
maxlength!: string|number; // This input is always defined, since the name matches selector.
470462

471463
/**
472464
* @description
@@ -547,17 +539,15 @@ export const PATTERN_VALIDATOR: any = {
547539
host: {'[attr.pattern]': 'pattern ? pattern : null'}
548540
})
549541
export class PatternValidator implements Validator, OnChanges {
550-
// TODO(issue/24571): remove '!'.
551-
private _validator!: ValidatorFn;
552-
// TODO(issue/24571): remove '!'.
553-
private _onChange!: () => void;
542+
private _validator: ValidatorFn = Validators.nullValidator;
543+
private _onChange?: () => void;
554544

555545
/**
556546
* @description
557547
* Tracks changes to the pattern bound to this directive.
558548
*/
559-
// TODO(issue/24571): remove '!'.
560-
@Input() pattern!: string|RegExp;
549+
@Input()
550+
pattern!: string|RegExp; // This input is always defined, since the name matches selector.
561551

562552
/**
563553
* @description

0 commit comments

Comments
 (0)