As for now, promise created by Bluebird does not have Symbol.toStringTag, but have toString method which returns "[object Promise]" string. Having [Symbol.toStringTag]: "Promise" make Object.prototype.toString.call(promise) to return same string: "[object Promise]" (as for now it will return "[object Object]" string.
So, I suggest to add Symbol.toStringTag property to bluebird's promise prototype.
I don't know how I feel about this. How would users be able to tell native promises apart?
import * as Bluebird from 'bluebird';
console.log(Promise.toString().includes('[native code]')); //true
const NativePromise = global.Promise;
global.Promise = Bluebird;
console.log(Promise.toString().includes('[native code]')); //false
const a = Promise.resolve();
console.log(a instanceof NativePromise); //false
console.log(a instanceof Promise); //true
function isNativePromise(promise: Promise<any>) {
return promise.constructor.toString().includes('[native code]');
}
The fact that Bluebird promises and native ES6 promises are incompatible makes it very difficult to work with packages like Sequelize in TypeScript. Please consider implementing this change.
I don't understand why you think bluebird is incompatible with native promises in TypeScript - I've been happily using them together for quite a while. That fact is unrelated to how toStringTag behaves.
They cannot be passed where a native promise is required as an argument due to the missing toStringTag symbol.
Theoretically, the .d.ts file could contain it -- however, DT maintainers are reluctant to add something that does not exist (and with good reason):
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11027#issuecomment-250976787
We should definitely do this, the only questions are:
Object.prototype.toString.call(promise) returns the same thing it did before[Symbol.toStringTag] directly to tell native from BB promises apart.
Most helpful comment
The fact that Bluebird promises and native ES6 promises are incompatible makes it very difficult to work with packages like Sequelize in TypeScript. Please consider implementing this change.