Rxjs: Runtime error: Observable.throw is not a function

Created on 23 May 2018  路  3Comments  路  Source: ReactiveX/rxjs

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.

Most helpful comment

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

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewwithanm picture matthewwithanm  路  4Comments

benlesh picture benlesh  路  3Comments

shenlin192 picture shenlin192  路  3Comments

peterbakonyi05 picture peterbakonyi05  路  4Comments

LittleFox94 picture LittleFox94  路  3Comments