Issue
private transactions = new BehaviorSubject([]);
getTransactions(): Observable<ITransaction[]> {
return this.transactions.asObservable();
}
checkTransactionsExist():Observable<boolean> {
return this.getTransactions().pipe(map((results:any) => results.length > 0 ? true));
} // i need to check data exist of transactions
But i am getting below error..What did i wrong please let me know
EROR:
- Argument of type 'unknown[]' is not assignable to parameter of type 'OperatorFunction<ITransaction[], boolean>'. Type 'unknown[]' provides no match for the signature '(source: Observable<ITransaction[]>): Observable'.
EDIT: i need to check transactions behavior subject array..i need return true if data exist or false
Solution
Try the following to help resolve this error. This is adding types and also updating the ternary statement which is invalid. It's invalid because you don't have the else condition. That being said, you can just simplify the return. results.length > 0
is the same as results.length > 0 ? true : false
:
private transactions = new BehaviorSubject<ITransaction[]>([]);
getTransactions(): Observable<ITransaction[]> {
return this.transactions.asObservable();
}
checkTransactionsExist():Observable<boolean> {
return this.getTransactions().pipe(map((results:ITransaction[]) => results.length > 0));
}
Answered By - Alexander Staroselsky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.