Runtime error: Observable.throw is not a function

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.

1 possible answer(s) on “Runtime error: Observable.throw is not a function

  1. 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');