ember-cli-typescript icon indicating copy to clipboard operation
ember-cli-typescript copied to clipboard

PromiseProxyMixin uses RSVP.Promise which is incompatible with native Promises

Open boris-petrov opened this issue 7 years ago • 2 comments

We discussed this in these two comments - here and here.

The problem is that PromiseProxyMixin uses RSVP.Promise in its type definition which makes it impossible to work with in TypeScript using native promises. And because Ember.js will be moving away from using RSVP at some point, this has to be figured out.

boris-petrov avatar Oct 15 '18 07:10 boris-petrov

In the typings we've written, we've made a point to capture what the types actually are, and so long as Ember is using RSVP, we want the types to model that accurately (so we won't be changing them any time soon!).

It's often possible to use PromiseLike<T> instead of Promise<T> in your types, thought that doesn't solve behavior around async or await. It's also fine to do a type-cast: as Promise. RSVP.Promise is (by definition of its conformance to the A+ Promises spec) a strict superset of the native Promise type, and so will work for type purposes as a native Promise. In short, you should be able use an RSVP.Promise anywhere native Promise is desired, but not necessarily vice versa.

chriskrycho avatar Oct 15 '18 23:10 chriskrycho

It might be nice to have a section of the docs describing how one might override this kind of thing in their own project

For world-class web developer training: https://mike.works


From: Chris Krycho [email protected] Sent: Monday, October 15, 2018 4:10:27 PM To: typed-ember/ember-cli-typescript Cc: Subscribed Subject: Re: [typed-ember/ember-cli-typescript] PromiseProxyMixin uses RSVP.Promise which is incompatible with native Promises (#341)

In the typings we've written, we've made a point to capture what the types actually are, and so long as Ember is using RSVP, we want the types to model that accurately (so we won't be changing them any time soon!).

It's often possible to use PromiseLike<T> instead of Promise<T> in your types, thought that doesn't solve behavior around async or await. It's also fine to do a type-cast: as Promise. RSVP.Promise is (by definition of its conformance to the A+ Promises spec) a strict superset of the native Promise type, and so will work for type purposes as a native Promise. In short, you should be able use an RSVP.Promise anywhere native Promise is desired, but not necessarily vice versa.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/typed-ember/ember-cli-typescript/issues/341#issuecomment-430045073, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAiDtU77W7PsC6t3f4Pc37QmrbqY5w79ks5ulRXjgaJpZM4XbyAd.

mike-north avatar Oct 16 '18 00:10 mike-north

This has largely been resolved by way of a few changes:

  1. We improved the types in this space (esp. for RSVP’s Promise compatibility) over time as TS afforded it.
  2. We changed how we represent mixins, especially in Ember's stable types.
  3. The Ember ecosystem has almost entirely moved away from PromiseProxyMixin, and it is in a position that it could be deprecated with effectively no churn.

Closing this accordingly!

chriskrycho avatar Sep 28 '23 22:09 chriskrycho