I'm trying to get my head around Reactive programming and observables, unsuccessfully of course. I have the following code:
this.searchSubscription = this.filtersSubject
.takeLast(2)
.reduce((acc, cur) => {
console.log(acc);
acc.push(cur);
return acc;
}, [])
.debounceTime(1000)
.subscribe(x => this.emitFilters());
I wanted to use takeLast(2) piped to reduce so I could turn it into an array of two values, and the filter is certain values between the two were different. I've been going over the docs for reduce, even passing a seed, but VS Code tells me that Property 'push' does not exist on type 'Object'. but the console.log shows acc to be an array. I'm baffled at what's going on and how to fix it. And of course, I may be tackling this problem entirely wrong, which is making observables hard enough to understand.