我是 angular 的初学者。我在服务中创建了一个方法,在该方法中我验证了 json 文件中用户的存在。但是,我收到了这个错误:
Argument of type 'OperatorFunction<any[], any[]>' is not assignable to parameter of type 'OperatorFunction<Object, any[]>'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'any[]': length, pop, push, concat, and 26 more.ts(2345)
custom-validation.service.ts
validateUserNameNotTaken(control: AbstractControl){
return this.checkUsernameNotTaken(control.value).pipe(
map(res=> {
return res ? null :{usernameTaken : true};
})
);
}
checkUsernameNotTaken(username: string): Observable<boolean> {
return this.http.get("assets/fakedb.json").pipe( map((usernameList: Array<any>) => usernameList.filter(user => user.username === username) ),
map(users => !users.length)
);
}