ember-cli-typescript
ember-cli-typescript copied to clipboard
PromiseProxyMixin uses RSVP.Promise which is incompatible with native Promises
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.
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.
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.
This has largely been resolved by way of a few changes:
- We improved the types in this space (esp. for RSVP’s
Promisecompatibility) over time as TS afforded it. - We changed how we represent mixins, especially in Ember's stable types.
- 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!