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:
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.
Most helpful comment
@mebibou Don't pipe. It's on the Observable object by default.