From 01e869a45be7cdcf2f103ddd3ec16d844eff6181 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 7 Jun 2021 21:04:52 +0200 Subject: [PATCH] refactor(forms): ensure compatibility with noImplicitOverride (#42512) Adds the `override` keyword to the `forms` sources to ensure compatibility with `noImplicitOverride`. PR Close #42512 --- .../src/directives/abstract_form_group_directive.ts | 4 ++-- packages/forms/src/directives/control_container.ts | 2 +- packages/forms/src/directives/ng_form.ts | 4 ++-- packages/forms/src/directives/ng_model.ts | 4 ++-- packages/forms/src/directives/ng_model_group.ts | 4 ++-- packages/forms/src/directives/number_value_accessor.ts | 2 +- .../src/directives/radio_control_value_accessor.ts | 4 ++-- packages/forms/src/directives/range_value_accessor.ts | 2 +- .../reactive_directives/form_control_directive.ts | 2 +- .../reactive_directives/form_control_name.ts | 4 ++-- .../reactive_directives/form_group_directive.ts | 4 ++-- .../directives/reactive_directives/form_group_name.ts | 10 +++++----- .../src/directives/select_control_value_accessor.ts | 2 +- .../select_multiple_control_value_accessor.ts | 2 +- packages/forms/src/directives/validators.ts | 2 +- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/forms/src/directives/abstract_form_group_directive.ts b/packages/forms/src/directives/abstract_form_group_directive.ts index d5497344ec..c657f10ae3 100644 --- a/packages/forms/src/directives/abstract_form_group_directive.ts +++ b/packages/forms/src/directives/abstract_form_group_directive.ts @@ -60,7 +60,7 @@ export class AbstractFormGroupDirective extends ControlContainer implements OnIn * @description * The path to this group from the top-level directive. */ - get path(): string[] { + override get path(): string[] { return controlPath(this.name == null ? this.name : this.name.toString(), this._parent); } @@ -68,7 +68,7 @@ export class AbstractFormGroupDirective extends ControlContainer implements OnIn * @description * The top-level directive for this group if present, otherwise null. */ - get formDirective(): Form|null { + override get formDirective(): Form|null { return this._parent ? this._parent.formDirective : null; } diff --git a/packages/forms/src/directives/control_container.ts b/packages/forms/src/directives/control_container.ts index 3b160a686f..9c88665dd4 100644 --- a/packages/forms/src/directives/control_container.ts +++ b/packages/forms/src/directives/control_container.ts @@ -37,7 +37,7 @@ export abstract class ControlContainer extends AbstractControlDirective { * @description * The path to this group. */ - get path(): string[]|null { + override get path(): string[]|null { return null; } } diff --git a/packages/forms/src/directives/ng_form.ts b/packages/forms/src/directives/ng_form.ts index b91cf56786..16e2a4aaa7 100644 --- a/packages/forms/src/directives/ng_form.ts +++ b/packages/forms/src/directives/ng_form.ts @@ -148,7 +148,7 @@ export class NgForm extends ControlContainer implements Form, AfterViewInit { * @description * The directive instance. */ - get formDirective(): Form { + override get formDirective(): Form { return this; } @@ -165,7 +165,7 @@ export class NgForm extends ControlContainer implements Form, AfterViewInit { * Returns an array representing the path to this group. Because this directive * always lives at the top level of a form, it is always an empty array. */ - get path(): string[] { + override get path(): string[] { return []; } diff --git a/packages/forms/src/directives/ng_model.ts b/packages/forms/src/directives/ng_model.ts index db0b593505..40d9a26ce9 100644 --- a/packages/forms/src/directives/ng_model.ts +++ b/packages/forms/src/directives/ng_model.ts @@ -162,7 +162,7 @@ export class NgModel extends NgControl implements OnChanges, OnDestroy { * uses this name as a key to retrieve this control's value. */ // TODO(issue/24571): remove '!'. - @Input() name!: string; + @Input() override name!: string; /** * @description @@ -240,7 +240,7 @@ export class NgModel extends NgControl implements OnChanges, OnDestroy { * Returns an array that represents the path from the top-level form to this control. * Each index is the string name of the control on that level. */ - get path(): string[] { + override get path(): string[] { return this._parent ? controlPath(this.name, this._parent) : [this.name]; } diff --git a/packages/forms/src/directives/ng_model_group.ts b/packages/forms/src/directives/ng_model_group.ts index 434a4de918..fd723939a4 100644 --- a/packages/forms/src/directives/ng_model_group.ts +++ b/packages/forms/src/directives/ng_model_group.ts @@ -55,7 +55,7 @@ export class NgModelGroup extends AbstractFormGroupDirective implements OnInit, * to a key in the parent `NgForm`. */ // TODO(issue/24571): remove '!'. - @Input('ngModelGroup') name!: string; + @Input('ngModelGroup') override name!: string; constructor( @Host() @SkipSelf() parent: ControlContainer, @@ -69,7 +69,7 @@ export class NgModelGroup extends AbstractFormGroupDirective implements OnInit, } /** @internal */ - _checkParentType(): void { + override _checkParentType(): void { if (!(this._parent instanceof NgModelGroup) && !(this._parent instanceof NgForm) && (typeof ngDevMode === 'undefined' || ngDevMode)) { TemplateDrivenErrors.modelGroupParentException(); diff --git a/packages/forms/src/directives/number_value_accessor.ts b/packages/forms/src/directives/number_value_accessor.ts index 8164453746..103b4bc580 100644 --- a/packages/forms/src/directives/number_value_accessor.ts +++ b/packages/forms/src/directives/number_value_accessor.ts @@ -62,7 +62,7 @@ export class NumberValueAccessor extends BuiltInControlValueAccessor implements * Registers a function called when the control value changes. * @nodoc */ - registerOnChange(fn: (_: number|null) => void): void { + override registerOnChange(fn: (_: number|null) => void): void { this.onChange = (value) => { fn(value == '' ? null : parseFloat(value)); }; diff --git a/packages/forms/src/directives/radio_control_value_accessor.ts b/packages/forms/src/directives/radio_control_value_accessor.ts index 0820e588ac..e25a2a2477 100644 --- a/packages/forms/src/directives/radio_control_value_accessor.ts +++ b/packages/forms/src/directives/radio_control_value_accessor.ts @@ -129,7 +129,7 @@ export class RadioControlValueAccessor extends BuiltInControlValueAccessor imple * `BaseControlValueAccessor` class. * @nodoc */ - onChange = () => {}; + override onChange = () => {}; /** * @description @@ -183,7 +183,7 @@ export class RadioControlValueAccessor extends BuiltInControlValueAccessor imple * Registers a function called when the control value changes. * @nodoc */ - registerOnChange(fn: (_: any) => {}): void { + override registerOnChange(fn: (_: any) => {}): void { this._fn = fn; this.onChange = () => { fn(this.value); diff --git a/packages/forms/src/directives/range_value_accessor.ts b/packages/forms/src/directives/range_value_accessor.ts index 5c74cba682..6224a37b76 100644 --- a/packages/forms/src/directives/range_value_accessor.ts +++ b/packages/forms/src/directives/range_value_accessor.ts @@ -64,7 +64,7 @@ export class RangeValueAccessor extends BuiltInControlValueAccessor implements * Registers a function called when the control value changes. * @nodoc */ - registerOnChange(fn: (_: number|null) => void): void { + override registerOnChange(fn: (_: number|null) => void): void { this.onChange = (value) => { fn(value == '' ? null : parseFloat(value)); }; diff --git a/packages/forms/src/directives/reactive_directives/form_control_directive.ts b/packages/forms/src/directives/reactive_directives/form_control_directive.ts index ba7bace32d..53abe71a9d 100644 --- a/packages/forms/src/directives/reactive_directives/form_control_directive.ts +++ b/packages/forms/src/directives/reactive_directives/form_control_directive.ts @@ -149,7 +149,7 @@ export class FormControlDirective extends NgControl implements OnChanges, OnDest * Returns an array that represents the path from the top-level form to this control. * Each index is the string name of the control on that level. */ - get path(): string[] { + override get path(): string[] { return []; } diff --git a/packages/forms/src/directives/reactive_directives/form_control_name.ts b/packages/forms/src/directives/reactive_directives/form_control_name.ts index fe5044c6ed..fb300c6942 100644 --- a/packages/forms/src/directives/reactive_directives/form_control_name.ts +++ b/packages/forms/src/directives/reactive_directives/form_control_name.ts @@ -87,7 +87,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy { * to indices when iterating over controls in a `FormArray`. */ // TODO(issue/24571): remove '!'. - @Input('formControlName') name!: string|number|null; + @Input('formControlName') override name!: string|number|null; /** * @description @@ -176,7 +176,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy { * Returns an array that represents the path from the top-level form to this control. * Each index is the string name of the control on that level. */ - get path(): string[] { + override get path(): string[] { return controlPath(this.name == null ? this.name : this.name.toString(), this._parent!); } diff --git a/packages/forms/src/directives/reactive_directives/form_group_directive.ts b/packages/forms/src/directives/reactive_directives/form_group_directive.ts index f8ab4a62a9..fe62635272 100644 --- a/packages/forms/src/directives/reactive_directives/form_group_directive.ts +++ b/packages/forms/src/directives/reactive_directives/form_group_directive.ts @@ -132,7 +132,7 @@ export class FormGroupDirective extends ControlContainer implements Form, OnChan * @description * Returns this directive's instance. */ - get formDirective(): Form { + override get formDirective(): Form { return this; } @@ -149,7 +149,7 @@ export class FormGroupDirective extends ControlContainer implements Form, OnChan * Returns an array representing the path to this group. Because this directive * always lives at the top level of a form, it always an empty array. */ - get path(): string[] { + override get path(): string[] { return []; } diff --git a/packages/forms/src/directives/reactive_directives/form_group_name.ts b/packages/forms/src/directives/reactive_directives/form_group_name.ts index b941e65e72..7205397f76 100644 --- a/packages/forms/src/directives/reactive_directives/form_group_name.ts +++ b/packages/forms/src/directives/reactive_directives/form_group_name.ts @@ -82,7 +82,7 @@ export class FormGroupName extends AbstractFormGroupDirective implements OnInit, * to indices when iterating over groups in a `FormArray`. */ // TODO(issue/24571): remove '!'. - @Input('formGroupName') name!: string|number|null; + @Input('formGroupName') override name!: string|number|null; constructor( @Optional() @Host() @SkipSelf() parent: ControlContainer, @@ -96,7 +96,7 @@ export class FormGroupName extends AbstractFormGroupDirective implements OnInit, } /** @internal */ - _checkParentType(): void { + override _checkParentType(): void { if (_hasInvalidParent(this._parent) && (typeof ngDevMode === 'undefined' || ngDevMode)) { ReactiveErrors.groupParentException(); } @@ -147,7 +147,7 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy * to indices when iterating over arrays in a `FormArray`. */ // TODO(issue/24571): remove '!'. - @Input('formArrayName') name!: string|number|null; + @Input('formArrayName') override name!: string|number|null; constructor( @Optional() @Host() @SkipSelf() parent: ControlContainer, @@ -192,7 +192,7 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy * @description * The top-level directive for this group if present, otherwise null. */ - get formDirective(): FormGroupDirective|null { + override get formDirective(): FormGroupDirective|null { return this._parent ? this._parent.formDirective : null; } @@ -201,7 +201,7 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy * Returns an array that represents the path from the top-level form to this control. * Each index is the string name of the control on that level. */ - get path(): string[] { + override get path(): string[] { return controlPath(this.name == null ? this.name : this.name.toString(), this._parent); } diff --git a/packages/forms/src/directives/select_control_value_accessor.ts b/packages/forms/src/directives/select_control_value_accessor.ts index ee6c4cca40..3689bc8f75 100644 --- a/packages/forms/src/directives/select_control_value_accessor.ts +++ b/packages/forms/src/directives/select_control_value_accessor.ts @@ -133,7 +133,7 @@ export class SelectControlValueAccessor extends BuiltInControlValueAccessor impl * Registers a function called when the control value changes. * @nodoc */ - registerOnChange(fn: (value: any) => any): void { + override registerOnChange(fn: (value: any) => any): void { this.onChange = (valueString: string) => { this.value = this._getOptionValue(valueString); fn(this.value); diff --git a/packages/forms/src/directives/select_multiple_control_value_accessor.ts b/packages/forms/src/directives/select_multiple_control_value_accessor.ts index 0adf312cf7..151194afb1 100644 --- a/packages/forms/src/directives/select_multiple_control_value_accessor.ts +++ b/packages/forms/src/directives/select_multiple_control_value_accessor.ts @@ -136,7 +136,7 @@ export class SelectMultipleControlValueAccessor extends BuiltInControlValueAcces * and writes an array of the selected options. * @nodoc */ - registerOnChange(fn: (value: any) => any): void { + override registerOnChange(fn: (value: any) => any): void { this.onChange = (_: any) => { const selected: Array = []; if (_.selectedOptions !== undefined) { diff --git a/packages/forms/src/directives/validators.ts b/packages/forms/src/directives/validators.ts index 53b53d2450..b6ed662b55 100644 --- a/packages/forms/src/directives/validators.ts +++ b/packages/forms/src/directives/validators.ts @@ -410,7 +410,7 @@ export class CheckboxRequiredValidator extends RequiredValidator { * Returns the validation result if enabled, otherwise null. * @nodoc */ - validate(control: AbstractControl): ValidationErrors|null { + override validate(control: AbstractControl): ValidationErrors|null { return this.required ? requiredTrueValidator(control) : null; } }