After updating to the latest version of RxJS and converting all the imports, methods, and operators to the new syntax, I encountered a type error at runtime stating that Observable.of
is not recognized as a function. This same issue also occurs with methods defined as part of an extension of Observable
, such as Observable.fromEvent
.
Interestingly, stand alone functions like Observable.combineLatest
work fine despite the compiler warning that they do not exist on type Observable
.
To resolve this problem, I had to make the following changes:
import { of } from 'rxjs/observable/of';
import { fromEvent } from 'rxjs/observable/fromEvent';
...
const x = Observable.of(true, false);
const y = Observable.fromEvent(target, 'click');
I replaced it with:
import { ArrayObservable } from 'rxjs/observable/ArrayObservable';
import { FromEventObservable } from 'rxjs/observable/FromEventObservable';
...
const x = ArrayObservable.of(true, false);
const y = FromEventObservable.create(target, 'click');
However, I believe there may be a better solution available. Am I correct?
Additional Notes:
- I am required to use "Ahead Of Time compilation" feature for building and serving the app, as without it the angular injector fails.
- I have come across another similar question on Stack Overflow, but it pertains to older versions of RxJS before 5.5.
ng --version
outputs:Angular CLI: 1.6.3, Node: 8.9.1, OS: win32 x64, Angular: 5.1.3,
@angular/cli: 1.6.3, @angular-devkit/build-optimizer: 0.0.36, @angular-devkit/core: 0.0.22, @angular-devkit/schematics: 0.0.42, @ngtools/json-schema: 1.1.0, @ngtools/webpack: 1.9.3, @schematics/angular: 0.1.11, @schematics/schematics: 0.0.11, typescript: 2.5.3, webpack: 3.10.0,