Mario Goller
Mario Goller

Reputation: 41

Breaking change in RxJs ErrorObservable (Migration 5 -> 6)

We're facing an issue while updating our application to RxJs 6 (with rxjs-compat). A referenced library, which is still on RxJs 5 is using ErrorObservable as a return type of a method.

public handleError(error: Error): ErrorObservable {
    ...
    return Observable.throw('some error message');
}

As of now ErrorObservable is a non-generic type in RxJs: https://github.com/ReactiveX/rxjs/blob/5.5.11/src/observable/ErrorObservable.ts

export class ErrorObservable extends Observable<any> {
  ...
}

This has changed with RxJs 6
(see https://github.com/ReactiveX/rxjs/blob/master/compat/observable/ErrorObservable.ts)

export class ErrorObservable<T> extends Observable<T> {
  static create<T>(error: any, scheduler?: SchedulerLike) {
    return throwError(error, scheduler);
  }
}

Which of course leads to a compile error:

ERROR in ... : error TS2314: Generic type 'ErrorObservable<T>' requires 1 type argument(s).

Is this a case, which is not covered by rxjs-compat or is it an issue with the type definition in rxjs-compat?

Upvotes: 4

Views: 4407

Answers (1)

skyboyer
skyboyer

Reputation: 23705

Take a look into breaking-changes section

All observable classes (https://github.com/ReactiveX/rxjs/tree/5.5.8/src/observable) have been removed from v6, in favor of existing or new operators that perform the same operations as the class methods. For example, ArrayObservable.create(myArray) can be replaced by from(myArray), or the new operator fromArray()

It seems you should use throwError function instead of ErrorObservable class.

Upvotes: 4

Related Questions