-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add Symbol.toStringTag to promise instance #1277
Comments
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): |
We should definitely do this, the only questions are:
|
As for now, promise created by Bluebird does not have
Symbol.toStringTag
, but havetoString
method which returns"[object Promise]"
string. Having[Symbol.toStringTag]: "Promise"
makeObject.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.The text was updated successfully, but these errors were encountered: