I have a code in which the memberships$ is an observable of objects that have a property "role". I want to use reduce function in order to traverse all of them, and if anyone's role is "Collector" I want to return value true. This is the code:
hasCollectorRole$: Observable<boolean> = this.memberships$.pipe(
map(arr => {
return arr.reduce((acc, val) => {
if (val.role == "Collector") {
acc = true;
}
return acc;
}, false)
})
);
This is the error that I get on it:
Type 'true' is not assignable to type 'false'.
How do I fix this?