alvipeo alvipeo - 11 months ago 143
TypeScript Question

import .of() for Observable in typescript

I'm using this great repo for my angular 2 test project (TypeScript) - And I need to use Observable.of(..). When I try to import it:

import { Observable } from "rxjs/Observable";
import { of } from 'rxjs/observable/of';

I get:

Property 'of' does not exist on type 'typeof Observable'.

I also tried it the following way:

import { Observable } from "rxjs/Observable";
import { of } from 'rxjs/add/observable/of'; // notice 'add'

I got:

node_modules/rxjs/add/observable/of"' has no exported member 'of'.

So, how can one import this Of() static method for Observable???

Answer Source

You do not have to import {of} from 'rxjs/add/observable/of'. You can directly use

import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/of";

Or you can import Observable from "rxjs/Rx" which bundle all the operators.

import { Observable } from "rxjs/Rx";