How to import RXJS types for TypeScript

atomrc

If I understand correctly, rxjs (version 5) is written in typescript and is packaged with all the definitions.

I tried using them, but I cannot seem to find a way to do that. I get the error

error TS2304: Cannot find name 'Observable'

Here is my tsconfg.json

{
  "compilerOptions": {
    "target": "es2016",
    "strict": true
  },
  "exclude": [ "node_modules" ]
}

and the file I try to compile

const { Observable } = require("@reactivex/rxjs")

function timer(time: Number): Observable {
  return Observable.timer(time)
}

I run node_modules/.bin/tsc test.ts

Am I missing some typescript config here? Is there something to do to enable types?

edzillion

The typescript definitions for Observable Subject etc from RXJS are bundled and installed with the RXJS package. So if you run npm install rxjs you will get the type description files (*.td) included in the npm module.

In this case I think your issue is with the import of the Observable module. It should read:

import { Observable } from 'rxjs/Observable';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related