fix(forms): Update types for TypeScript nullability support

This reverts commit 2e47a0d19f.
This commit is contained in:
Miško Hevery
2017-04-14 13:59:08 -07:00
committed by Tobias Bosch
parent 56c46d70f7
commit 6649743a2d
27 changed files with 343 additions and 330 deletions

View File

@ -143,9 +143,11 @@ export class Validators {
* Compose multiple validators into a single function that returns the union
* of the individual error maps.
*/
static compose(validators: ValidatorFn[]): ValidatorFn {
static compose(validators: null): null;
static compose(validators: (ValidatorFn|null|undefined)[]): ValidatorFn|null;
static compose(validators: (ValidatorFn|null|undefined)[]|null): ValidatorFn|null {
if (!validators) return null;
const presentValidators = validators.filter(isPresent);
const presentValidators: ValidatorFn[] = validators.filter(isPresent) as any;
if (presentValidators.length == 0) return null;
return function(control: AbstractControl) {
@ -153,9 +155,9 @@ export class Validators {
};
}
static composeAsync(validators: AsyncValidatorFn[]): AsyncValidatorFn {
static composeAsync(validators: (AsyncValidatorFn|null)[]): AsyncValidatorFn|null {
if (!validators) return null;
const presentValidators = validators.filter(isPresent);
const presentValidators: AsyncValidatorFn[] = validators.filter(isPresent) as any;
if (presentValidators.length == 0) return null;
return function(control: AbstractControl) {
@ -188,7 +190,7 @@ function _executeAsyncValidators(control: AbstractControl, validators: AsyncVali
function _mergeErrors(arrayOfErrors: ValidationErrors[]): ValidationErrors|null {
const res: {[key: string]: any} =
arrayOfErrors.reduce((res: ValidationErrors | null, errors: ValidationErrors | null) => {
return errors != null ? {...res, ...errors} : res;
return errors != null ? {...res !, ...errors} : res !;
}, {});
return Object.keys(res).length === 0 ? null : res;
}