refactor: add override keyword to members implementing abstract declarations (#42512)

In combination with the TS `noImplicitOverride` compatibility changes,
we also want to follow the best-practice of adding `override` to
members which are implemented as part of abstract classes. This
commit fixes all instances which will be flagged as part of the
custom `no-implicit-override-abstract` TSLint rule.

PR Close #42512
This commit is contained in:
Paul Gschwendtner
2021-07-07 19:58:22 +02:00
committed by Andrew Kushnir
parent 04642e7985
commit b5ab7aff43
113 changed files with 517 additions and 511 deletions
@@ -52,7 +52,7 @@ export class AbstractFormGroupDirective extends ControlContainer implements OnIn
* @description
* The `FormGroup` bound to this directive.
*/
get control(): FormGroup {
override get control(): FormGroup {
return this.formDirective!.getFormGroup(this);
}
+1 -1
View File
@@ -156,7 +156,7 @@ export class NgForm extends ControlContainer implements Form, AfterViewInit {
* @description
* The internal `FormGroup` instance.
*/
get control(): FormGroup {
override get control(): FormGroup {
return this.form;
}
+2 -2
View File
@@ -136,7 +136,7 @@ const resolvedPromise = (() => Promise.resolve(null))();
exportAs: 'ngModel'
})
export class NgModel extends NgControl implements OnChanges, OnDestroy {
public readonly control: FormControl = new FormControl();
public override readonly control: FormControl = new FormControl();
// At runtime we coerce arbitrary values assigned to the "disabled" input to a "boolean".
// This is not reflected in the type of the property because outside of templates, consumers
@@ -258,7 +258,7 @@ export class NgModel extends NgControl implements OnChanges, OnDestroy {
*
* @param newValue The new value emitted by `ngModelChange`.
*/
viewToModelUpdate(newValue: any): void {
override viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
this.update.emit(newValue);
}
@@ -157,7 +157,7 @@ export class FormControlDirective extends NgControl implements OnChanges, OnDest
* @description
* The `FormControl` bound to this directive.
*/
get control(): FormControl {
override get control(): FormControl {
return this.form;
}
@@ -167,7 +167,7 @@ export class FormControlDirective extends NgControl implements OnChanges, OnDest
*
* @param newValue The new value for the view model.
*/
viewToModelUpdate(newValue: any): void {
override viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
this.update.emit(newValue);
}
@@ -75,7 +75,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
* Tracks the `FormControl` instance bound to the directive.
*/
// TODO(issue/24571): remove '!'.
readonly control!: FormControl;
override readonly control!: FormControl;
/**
* @description
@@ -166,7 +166,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
*
* @param newValue The new value for the view model.
*/
viewToModelUpdate(newValue: any): void {
override viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
this.update.emit(newValue);
}
@@ -140,7 +140,7 @@ export class FormGroupDirective extends ControlContainer implements Form, OnChan
* @description
* Returns the `FormGroup` bound to this directive.
*/
get control(): FormGroup {
override get control(): FormGroup {
return this.form;
}
@@ -184,7 +184,7 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
* @description
* The `FormArray` bound to this directive.
*/
get control(): FormArray {
override get control(): FormArray {
return this.formDirective!.getFormArray(this);
}
+6 -6
View File
@@ -176,11 +176,11 @@ export class MaxValidator extends AbstractValidatorDirective implements OnChange
*/
@Input() max!: string|number;
/** @internal */
inputName = 'max';
override inputName = 'max';
/** @internal */
normalizeInput = (input: string): number => parseFloat(input);
override normalizeInput = (input: string): number => parseFloat(input);
/** @internal */
createValidator = (max: number): ValidatorFn => maxValidator(max);
override createValidator = (max: number): ValidatorFn => maxValidator(max);
/**
* Declare `ngOnChanges` lifecycle hook at the main directive level (vs keeping it in base class)
* to avoid differences in handling inheritance of lifecycle hooks between Ivy and ViewEngine in
@@ -236,11 +236,11 @@ export class MinValidator extends AbstractValidatorDirective implements OnChange
*/
@Input() min!: string|number;
/** @internal */
inputName = 'min';
override inputName = 'min';
/** @internal */
normalizeInput = (input: string): number => parseFloat(input);
override normalizeInput = (input: string): number => parseFloat(input);
/** @internal */
createValidator = (min: number): ValidatorFn => minValidator(min);
override createValidator = (min: number): ValidatorFn => minValidator(min);
/**
* Declare `ngOnChanges` lifecycle hook at the main directive level (vs keeping it in base class)
* to avoid differences in handling inheritance of lifecycle hooks between Ivy and ViewEngine in
+27 -26
View File
@@ -1194,7 +1194,7 @@ export class FormControl extends AbstractControl {
* event to update the model.
*
*/
setValue(value: any, options: {
override setValue(value: any, options: {
onlySelf?: boolean,
emitEvent?: boolean,
emitModelToViewChange?: boolean,
@@ -1217,7 +1217,7 @@ export class FormControl extends AbstractControl {
*
* @see `setValue` for options
*/
patchValue(value: any, options: {
override patchValue(value: any, options: {
onlySelf?: boolean,
emitEvent?: boolean,
emitModelToViewChange?: boolean,
@@ -1244,7 +1244,8 @@ export class FormControl extends AbstractControl {
* When false, no events are emitted.
*
*/
reset(formState: any = null, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
override reset(formState: any = null, options: {onlySelf?: boolean, emitEvent?: boolean} = {}):
void {
this._applyFormState(formState);
this.markAsPristine(options);
this.markAsUntouched(options);
@@ -1255,19 +1256,19 @@ export class FormControl extends AbstractControl {
/**
* @internal
*/
_updateValue() {}
override _updateValue() {}
/**
* @internal
*/
_anyControls(condition: Function): boolean {
override _anyControls(condition: Function): boolean {
return false;
}
/**
* @internal
*/
_allControlsDisabled(): boolean {
override _allControlsDisabled(): boolean {
return this.disabled;
}
@@ -1308,10 +1309,10 @@ export class FormControl extends AbstractControl {
/**
* @internal
*/
_forEachChild(cb: Function): void {}
override _forEachChild(cb: Function): void {}
/** @internal */
_syncPendingControls(): boolean {
override _syncPendingControls(): boolean {
if (this.updateOn === 'submit') {
if (this._pendingDirty) this.markAsDirty();
if (this._pendingTouched) this.markAsTouched();
@@ -1564,8 +1565,8 @@ export class FormGroup extends AbstractControl {
* observables emit events with the latest status and value when the control value is updated.
* When false, no events are emitted.
*/
setValue(value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}):
void {
override setValue(
value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
this._checkAllValuesPresent(value);
Object.keys(value).forEach(name => {
this._throwIfControlMissing(name);
@@ -1605,8 +1606,8 @@ export class FormGroup extends AbstractControl {
* is updated. When false, no events are emitted. The configuration options are passed to
* the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
*/
patchValue(value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}):
void {
override patchValue(
value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
// Even though the `value` argument type doesn't allow `null` and `undefined` values, the
// `patchValue` can be called recursively and inner data structures might have these values, so
// we just ignore such cases when a field containing FormGroup instance receives `null` or
@@ -1678,7 +1679,7 @@ export class FormGroup extends AbstractControl {
* console.log(form.get('first').status); // 'DISABLED'
* ```
*/
reset(value: any = {}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
override reset(value: any = {}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
this._forEachChild((control: AbstractControl, name: string) => {
control.reset(value[name], {onlySelf: true, emitEvent: options.emitEvent});
});
@@ -1703,7 +1704,7 @@ export class FormGroup extends AbstractControl {
}
/** @internal */
_syncPendingControls(): boolean {
override _syncPendingControls(): boolean {
let subtreeUpdated = this._reduceChildren(false, (updated: boolean, child: AbstractControl) => {
return child._syncPendingControls() ? true : updated;
});
@@ -1725,7 +1726,7 @@ export class FormGroup extends AbstractControl {
}
/** @internal */
_forEachChild(cb: (v: any, k: string) => void): void {
override _forEachChild(cb: (v: any, k: string) => void): void {
Object.keys(this.controls).forEach(key => {
// The list of controls can change (for ex. controls might be removed) while the loop
// is running (as a result of invoking Forms API in `valueChanges` subscription), so we
@@ -1744,12 +1745,12 @@ export class FormGroup extends AbstractControl {
}
/** @internal */
_updateValue(): void {
override _updateValue(): void {
(this as {value: any}).value = this._reduceValue();
}
/** @internal */
_anyControls(condition: Function): boolean {
override _anyControls(condition: Function): boolean {
for (const controlName of Object.keys(this.controls)) {
const control = this.controls[controlName];
if (this.contains(controlName) && condition(control)) {
@@ -1780,7 +1781,7 @@ export class FormGroup extends AbstractControl {
}
/** @internal */
_allControlsDisabled(): boolean {
override _allControlsDisabled(): boolean {
for (const controlName of Object.keys(this.controls)) {
if (this.controls[controlName].enabled) {
return false;
@@ -2021,7 +2022,7 @@ export class FormArray extends AbstractControl {
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
* updateValueAndValidity} method.
*/
setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
override setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
this._checkAllValuesPresent(value);
value.forEach((newValue: any, index: number) => {
this._throwIfControlMissing(index);
@@ -2062,7 +2063,7 @@ export class FormArray extends AbstractControl {
* is updated. When false, no events are emitted. The configuration options are passed to
* the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
*/
patchValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
override patchValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
// Even though the `value` argument type doesn't allow `null` and `undefined` values, the
// `patchValue` can be called recursively and inner data structures might have these values, so
// we just ignore such cases when a field containing FormArray instance receives `null` or
@@ -2123,7 +2124,7 @@ export class FormArray extends AbstractControl {
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
* updateValueAndValidity} method.
*/
reset(value: any = [], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
override reset(value: any = [], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
this._forEachChild((control: AbstractControl, index: number) => {
control.reset(value[index], {onlySelf: true, emitEvent: options.emitEvent});
});
@@ -2188,7 +2189,7 @@ export class FormArray extends AbstractControl {
}
/** @internal */
_syncPendingControls(): boolean {
override _syncPendingControls(): boolean {
let subtreeUpdated = this.controls.reduce((updated: boolean, child: AbstractControl) => {
return child._syncPendingControls() ? true : updated;
}, false);
@@ -2210,21 +2211,21 @@ export class FormArray extends AbstractControl {
}
/** @internal */
_forEachChild(cb: Function): void {
override _forEachChild(cb: Function): void {
this.controls.forEach((control: AbstractControl, index: number) => {
cb(control, index);
});
}
/** @internal */
_updateValue(): void {
override _updateValue(): void {
(this as {value: any}).value =
this.controls.filter((control) => control.enabled || this.disabled)
.map((control) => control.value);
}
/** @internal */
_anyControls(condition: Function): boolean {
override _anyControls(condition: Function): boolean {
return this.controls.some((control: AbstractControl) => control.enabled && condition(control));
}
@@ -2243,7 +2244,7 @@ export class FormArray extends AbstractControl {
}
/** @internal */
_allControlsDisabled(): boolean {
override _allControlsDisabled(): boolean {
for (const control of this.controls) {
if (control.enabled) return false;
}