我正在构建一个基于graphQL的Angular应用程序,其中包含一些用于反应形式的自定义异步验证器。下面的此验证器尤其正在检查数据库中的电子邮件以查看其是否已经存在:
emailAsyncValidator: AsyncValidatorFn = (control: FormControl): Promise<ValidationErrors> | Observable<ValidationErrors> => {
return new Promise((res, _) => {
this.checkEmailGQL.fetch(control.value).pipe(map(result =>
result.data.checkEmail.matches ? res({emailExists: true}) : res(null)
), catchError((_) =>
of(res({asyncValidationFailed: true}))
))
});
}
但是,这会给我带来以下TS错误:
Type 'Observable<ValidationErrors>' is not assignable to type 'Promise<ValidationErrors> | Observable<ValidationErrors>'.
Type 'Observable<ValidationErrors>' is missing the following properties from type 'Observable<ValidationErrors>': _isScalar, source, operator, lift, and 6 more.ts(2322)
这里实际上是什么问题?预先感谢您的回答。