Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lettable toPromise? #2868

Closed
Delagen opened this issue Sep 26, 2017 · 10 comments
Closed

lettable toPromise? #2868

Delagen opened this issue Sep 26, 2017 · 10 comments
Assignees
Labels
bug Confirmed bug

Comments

@Delagen
Copy link
Contributor

Delagen commented Sep 26, 2017

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:

@Delagen
Copy link
Contributor Author

Delagen commented Sep 27, 2017

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

@benlesh
Copy link
Member

benlesh commented Sep 27, 2017

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

@benlesh benlesh closed this as completed Sep 27, 2017
@Delagen
Copy link
Contributor Author

Delagen commented Sep 28, 2017

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

@felixfbecker
Copy link
Contributor

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

const promise = toPromise()(myObservable)

@benlesh benlesh reopened this Oct 6, 2017
@benlesh
Copy link
Member

benlesh commented Oct 6, 2017

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.

@benlesh
Copy link
Member

benlesh commented Oct 6, 2017

cc @kwonoj

@benlesh benlesh self-assigned this Oct 6, 2017
@benlesh benlesh added the bug Confirmed bug label Oct 6, 2017
@benlesh benlesh closed this as completed in 031edca Oct 6, 2017
@mebibou
Copy link

mebibou commented Jan 5, 2018

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

@jack-guy
Copy link

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

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

@adrm
Copy link

adrm commented Feb 20, 2018

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

@lock
Copy link

lock bot commented Jun 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

6 participants