I have a problem trying to use RxJS with TypeScript and Node.js. I am using NPM, and I have included rxjs-es
version 5. I am also using Typings, and I have included both es6-shim
and rx.all
, like so:
{
"ambientDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654",
"rx.all": "registry:dt/rx.all#2.2.28+20160316155526"
}
}
Below is my tsconfig.json
file.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/browser",
"typings/browser.d.ts"
]
}
In a TypeScript file, I am trying to do the following:
import { Observable } from 'rxjs/Observable';
When I try to compile the script, I get the following error:
typings/main/ambient/rx.all/index.d.ts(10,11): error TS2304: Cannot find name 'Rx'.
This happens even if I try to use RxJS within my script or not, so the problem is related to the TypeScript typings.
What do I need to install using typings and NPM in order to use RxJS? In particular, I am interested in using Observables. After Googling for hours, I cannot seem to figure out just what I need to make it work. I have tried the following, but without any luck. I have also tried many combinations of rx packages in NPM and typings, but haven't found anything that works. Any help is much appreciated!
It's interesting to know that the RxJS project is using TypeScript actively and it helped to find bugs when the library was migrating from JavaScript.
RxJS is a JavaScript library that uses observables to work with reactive programming that deals with asynchronous data calls, callbacks and event-based programs. RxJS can be used with other JavaScript libraries and frameworks. It is supported by JavaScript and also with typescript.
Reactive Extensions for JavaScript, or RxJS, is a JavaScript library that uses observables for reactive programming. It can be used with other JavaScript libraries and frameworks, and it integrates well into Angular.
An Observable is a collection of multiple input values that get processed using array methods such as map , reduce , filter , and so on. It comes in handy when handling asynchronous operations such as making HTTP requests, user-input events, and so on.
RxJS 5 is written in typescript and its type definitions are included by default for published module, you may not need typings for rx.all
. Actually those type definitions are written for previous versions of RxJS. Simply uninstall rx.all
type definition and try to import without those.
The correct way of accomplishing this for Angular (not AngularJS) is by using @types from npm. The command is as follows:
npm install @types/rx --save-dev
For more information, see npm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With