poelstra / ts-promise

TS-Promise - fast, robust, type-safe promises
MIT License
45 stars 4 forks source link

External Promise interface iso full class #2

Closed rogierschouten closed 8 years ago

rogierschouten commented 9 years ago

Maybe it is a good idea to export a Promise base class with just the public stuff on it, instead of exporting the entire Promise class. I.e. rename the current class to PromiseImpl and return the Promise interface from all methods. This would cause many conflicts between promise libraries to disappear.

I just found an NPM module I potentially want to use that returns Bluebird promises, so we will keep mixing promises from different libraries. The Thenable interface is often too restrictive to use. The main reason that the Promise classes of Bluebird and ts-promise are incompatible is the existence of the private members of the ts-promise.Promise class.

Another solution would be to remove private members from the ts-promise typings file.

poelstra commented 9 years ago

I doubt it's just the private members, more likely different signatures of e.g. catch, but also 'missing' members such as map.

I was already thinking about adding an Es6Promise interface in addition to (and as superset of) Thenable, and have Promise implement it.

Will add this later.

On 3 juli 2015 15:14:51 GMT+07:00, Rogier Schouten notifications@github.com wrote:

Maybe it is a good idea to export a Promise base class with just the public stuff on it, instead of exporting the entire Promise class. I.e. rename the current class to PromiseImpl and return the Promise interface from all methods. This would cause many conflicts between promise libraries to disappear.

I just found an NPM module I potentially want to use that returns Bluebird promises, so we will keep mixing promises from different libraries. The Thenable interface is often too restrictive to use. The main reason that the Promise classes of Bluebird and ts-promise are incompatible is the existence of the private members of the ts-promise.Promise class.

Another solution would be to remove private members from the ts-promise typings file.


Reply to this email directly or view it on GitHub: https://github.com/poelstra/ts-promise/issues/2

poelstra commented 8 years ago

On further thought, adding an ES6 Promise interface won't really matter: it's already compatible with types that expect an ES6 promise (e.g. from TypeScript's lib.es2015.promise.d.ts).

I don't think there's a real advantage in providing another definition of a 'plain' ES6 Promise (in contrast to the Thenable interface, which is useful to have).

So closing this issue as wont-fix. Thanks for reporting, though!