fix(forms): Update types for TypeScript nullability support (#15859)

This commit is contained in:
Miško Hevery
2017-04-13 17:14:08 -07:00
committed by Tobias Bosch
parent fdb3f26448
commit 6a2e08d0a8
27 changed files with 343 additions and 330 deletions

View File

@ -88,8 +88,8 @@ export class FormControlDirective extends NgControl implements OnChanges {
ngOnChanges(changes: SimpleChanges): void {
if (this._isControlChanged(changes)) {
setUpControl(this.form, this);
if (this.control.disabled && this.valueAccessor.setDisabledState) {
this.valueAccessor.setDisabledState(true);
if (this.control.disabled && this.valueAccessor !.setDisabledState) {
this.valueAccessor !.setDisabledState !(true);
}
this.form.updateValueAndValidity({emitEvent: false});
}
@ -101,9 +101,9 @@ export class FormControlDirective extends NgControl implements OnChanges {
get path(): string[] { return []; }
get validator(): ValidatorFn { return composeValidators(this._rawValidators); }
get validator(): ValidatorFn|null { return composeValidators(this._rawValidators); }
get asyncValidator(): AsyncValidatorFn {
get asyncValidator(): AsyncValidatorFn|null {
return composeAsyncValidators(this._rawAsyncValidators);
}

View File

@ -125,14 +125,14 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
this.update.emit(newValue);
}
get path(): string[] { return controlPath(this.name, this._parent); }
get path(): string[] { return controlPath(this.name, this._parent !); }
get formDirective(): any { return this._parent ? this._parent.formDirective : null; }
get validator(): ValidatorFn { return composeValidators(this._rawValidators); }
get validator(): ValidatorFn|null { return composeValidators(this._rawValidators); }
get asyncValidator(): AsyncValidatorFn {
return composeAsyncValidators(this._rawAsyncValidators);
return composeAsyncValidators(this._rawAsyncValidators) !;
}
get control(): FormControl { return this._control; }
@ -151,8 +151,8 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
private _setUpControl() {
this._checkParentType();
this._control = this.formDirective.addControl(this);
if (this.control.disabled && this.valueAccessor.setDisabledState) {
this.valueAccessor.setDisabledState(true);
if (this.control.disabled && this.valueAccessor !.setDisabledState) {
this.valueAccessor !.setDisabledState !(true);
}
this._added = true;
}

View File

@ -69,7 +69,7 @@ export class FormGroupDirective extends ControlContainer implements Form,
private _oldForm: FormGroup;
directives: FormControlName[] = [];
@Input('formGroup') form: FormGroup = null;
@Input('formGroup') form: FormGroup = null !;
@Output() ngSubmit = new EventEmitter();
constructor(
@ -167,10 +167,10 @@ export class FormGroupDirective extends ControlContainer implements Form,
private _updateValidators() {
const sync = composeValidators(this._validators);
this.form.validator = Validators.compose([this.form.validator, sync]);
this.form.validator = Validators.compose([this.form.validator !, sync !]);
const async = composeAsyncValidators(this._asyncValidators);
this.form.asyncValidator = Validators.composeAsync([this.form.asyncValidator, async]);
this.form.asyncValidator = Validators.composeAsync([this.form.asyncValidator !, async !]);
}
private _checkFormPresent() {

View File

@ -166,7 +166,7 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
ngOnInit(): void {
this._checkParentType();
this.formDirective.addFormArray(this);
this.formDirective !.addFormArray(this);
}
ngOnDestroy(): void {
@ -175,17 +175,19 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
}
}
get control(): FormArray { return this.formDirective.getFormArray(this); }
get control(): FormArray { return this.formDirective !.getFormArray(this); }
get formDirective(): FormGroupDirective {
get formDirective(): FormGroupDirective|null {
return this._parent ? <FormGroupDirective>this._parent.formDirective : null;
}
get path(): string[] { return controlPath(this.name, this._parent); }
get validator(): ValidatorFn { return composeValidators(this._validators); }
get validator(): ValidatorFn|null { return composeValidators(this._validators); }
get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); }
get asyncValidator(): AsyncValidatorFn|null {
return composeAsyncValidators(this._asyncValidators);
}
private _checkParentType(): void {
if (_hasInvalidParent(this._parent)) {