1

So of course I googled a lot. For example this:

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

But what I try, it doesn't fix it.

So I have this:

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



export class TranslateServiceStub{

    public get(key: any): any {
        Observable.of(key);
    }
}

But it keeps saying this:


Property 'of' does not exist on type 'typeof Observable'.ts(2339)

So what do I have to do to fix this?

Thank you

Giannis
  • 1,790
  • 1
  • 11
  • 29

2 Answers2

1

import of from 'rxjs' not 'rxjs/observable/of';

import { of} from "rxjs";
Bilel-Zheni
  • 1,202
  • 1
  • 6
  • 10
  • I tried that. I type: Observable, and even don't see the of command –  Nov 12 '19 at 14:21
  • 1
    could you explain more about your requirements ? from what you want to create an observable ? – Bilel-Zheni Nov 12 '19 at 14:23
  • 1
    This is correct but OP is also doing `Observable.of` when the correct syntax is just `of()` – Liam Nov 12 '19 at 14:24
  • For the spec. I want to inject the mock in the spec file –  Nov 12 '19 at 14:28
  • 1
    @savantCodeEngineer, in Rxjs 6 you use only `of(key)` and `import { of} from "rxjs";`. From Angular 6 it's used Rxjs 6, if you are using an old Angular 5 your code is correct – Eliseo Nov 12 '19 at 15:00
0

If you are importing the function of from RxJS, why would you use it on observable ? just use it like that of(key). You don't have to call any object before that.

Nicolas
  • 8,077
  • 4
  • 21
  • 51