Search code examples
angularrxjsrxjs5

RxJs v5 in Angular5 - clickStream.bufer( () => clickStream.throttleTime(250)) etc fails


How can I do the following?

let button = document.querySelector('.this');
let clickStream = Observable.fromEvent(button, 'click');
let multiClickStream = clickStream
   .buffer(() => { return clickStream.throttleTime(250); } )
   .map(function(list) { return list.length; })
   .filter(function(x) { return x >= 2; });

The error message is:

TS2345: argument of type '()=> void' is not assignable to paramter of type Observabl. Property '_isScalar' is missing in type ()=>void

Alternatives like ".buffer(function() { return clickStream.throttleTime(250); }) " give a similar error.

I also tried throttle(250), but that does not work neither.


Solution

  • It looks like you wanted to use bufferWhen that accepts a function as an argument.

    Otherwise just pass the Observable directly to buffer without wrapping it:

    ...
    .buffer(clickStream.throttleTime(250))