2

I have this little snippet

const observable:Observable<number> = Observable.from([1, 2, 3])
  .reduce((sum: number, number: number) => {
    return sum + number
}, 0)
observable.subscribeOnNext((sum) => console.log(sum))

It works as expected, but the Typescript compiler produces this error:

error TS2339: Property 'reduce' does not exist on type 'Observable'.

If reduce is changed to scan, the error goes away (= the definition of scan is found by the compiler, but the definition of reduce not).

I'm using npm, and have typescript (2.0.10), rx (4.1.0) and @types/rx (2.5.34) installed.

2
  • It looks like a recent commit added typings, so you might be able to use that - try npm install --save Reactive-Extensions/RxJS (and remove the old version of RxJS and the types you have installed). Commented Dec 3, 2016 at 16:13
  • 1
    Yes, thats working, thanks! Do you want to post that as an actual answer, so I can accept? Commented Dec 3, 2016 at 17:26

2 Answers 2

1

The latest version of RxJS 4 on GitHub has added a typings declaration and the relevant d.ts files that define the types for TypeScript.

Simply upgrade to the latest version by removing the old rx and @types/rx modules and run:

npm install --save Reactive-Extensions/RxJS

Note the syntax Reactive-Extensions/RxJS which is shorthand for using the GitHub repository's source code.

Sign up to request clarification or add additional context in comments.

Comments

1

Another thing that generates this error is how you import Observable. I had

import {Observable} from 'rxjs/Observable'

which caused the same error, by changing it to

import {Observable} from 'rxjs/Rx'      

it resolved the reduce method correctly. Something else to check.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.