0
votes

Please, help me fix this error:

type IValidator = (value?: string) => string | undefined;
type IComposeValidators = (validators: ((value?: string) => string | undefined)[]) => IValidator;

export const composeValidators: IComposeValidators = (...validators) => (value) => {
  return validators.reduce((error, validator) => error || validator(value), undefined); // This expression is not callable. Type '((value?: string | undefined) => string | undefined)[]' has no call signatures.(2349)
};

Typescript Playground

1

1 Answers

0
votes

I finded solution:

type IValidator = (value?: string) => string | undefined;

export const composeValidators = (...validators: IValidator[]): IValidator => (value) => {
  return validators.reduce((error: string | undefined, validator) => error || validator(value), undefined);
};