Search code examples
javascripttypescriptrxjstypescript1.6

Typescript with Rx - count() function not found exception


I'm working in Typescript, writing an Angular2 application using Reactive. I'm not sure why but when I try to call .count() on an Rx observable I get the exception 'count is not a function'. The intellisense shows that .count() is a function and looking at the Rx source, I see the function. Below is some code that throws the exception:

myFunction(): void {
        console.log('made it');
        var x: Rx.Subject<number> = new Rx.Subject<number>();
        //var t = x.count();  //throws here
        var y = x.asObservable();
        var source = y.count(); //throws here
    }

TypeError: y.count is not a function


Solution

  • What happens if you try

    var t = (<any>x).count();
    

    ?

    My guess is that TypeScript definition files for Reactive (v2.5.3) lack behind official distribution (v4.0.6).