Rxjs: lettable toPromise?

Created on 26 Sep 2017  路  10Comments  路  Source: ReactiveX/rxjs

RxJS version: 5.5.0-beta

Code to reproduce:

import { of } from "rxjs/observable/of";
import {
    map,
    toPromise
} from "rxjs/operators";

export function demoFn(): Promise<void> {
    return of([null])
        .pipe(
            map(() => {}),
            toPromise()
        );
}

Expected behavior:
No error
Actual behavior:

Error:(11, 4) TS2345: Argument of type 'UnaryFunction<Observable<void>, Promise<void>>' is not assignable to parameter of type 'UnaryFunction<Observable<void>, Observable<{}>>'.
  Type 'Promise<void>' is not assignable to type 'Observable<{}>'.
    Property '_isScalar' is missing in type 'Promise<void>'.

Additional information:

bug

Most helpful comment

@mebibou Don't pipe. It's on the Observable object by default.

Observable.of('foo').toPromise(); // this
Observable.of('foo').pipe(toPromise()); // not this

All 10 comments

Any response? It works in result, but typechecking fails (

toPromise isn't really an operator, it's a means to subscribe to an observable. An operator would return an Observable.

@benlesh I understand it, but it exported as lettable. What the preferred way of convert to promise with support of tree shaking?

To support tree shaking I'd just use toPromise() as a static function, i.e.

const promise = toPromise()(myObservable)

but it exported as lettable

... Oops.

That doesn't seem right. Since it doesn't compose via pipe, it should probably be a method on Observable. Perhaps a permanent property? It would effect size a little, I suppose, but it's a pretty small function overall.

cc @kwonoj

So what is the proper way of using toPromise on Observable now?

@mebibou Don't pipe. It's on the Observable object by default.

Observable.of('foo').toPromise(); // this
Observable.of('foo').pipe(toPromise()); // not this

Thanks, @harangue , I hope pipeable operators docs were as clear on this :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chalin picture chalin  路  4Comments

Agraphie picture Agraphie  路  3Comments

cartant picture cartant  路  3Comments

giovannicandido picture giovannicandido  路  4Comments

matthewwithanm picture matthewwithanm  路  4Comments