RxJS version: 6.2.0
Code to reproduce:
https://stackblitz.com/edit/typescript-se5hib
import { Observable } from 'rxjs'
Observable.throw('hello')
Expected behavior:
It should not throws any exception, since it has passed typescript compilation.
Actual behavior:
Runtime error: Observable.throw is not a function
Additional information:
The implementation of Observable does not match its declaration. Also, Observable.if has same problem.
In v6 and higher you want to import throwError, that throw static method is an unfortunate necessity leftover from v5 compat.
import { throwError } from 'rxjs';
throwError('hello');
Sorry, the real issue should be that the implementation of Observable does not match its declaration. The delaration file tells me that I can use Observable.throw, but actually no. It's deleted rather than deprecated.
rxjs/internal/Observable.d.ts file link L69
Someone give this man a cookie!!! @benlesh
Most helpful comment
In v6 and higher you want to import
throwError, that throw static method is an unfortunate necessity leftover from v5 compat.