rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

Runtime error: Observable.throw is not a function

Open Zzzen opened this issue 8 years ago • 3 comments

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.

Zzzen avatar May 23 '18 07:05 Zzzen

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

benlesh avatar May 23 '18 17:05 benlesh

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

Zzzen avatar May 24 '18 02:05 Zzzen

Someone give this man a cookie!!! @benlesh

leomleao avatar Jun 04 '18 23:06 leomleao