Skip to content
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

Closed
Strate opened this issue Nov 4, 2016 · 7 comments · Fixed by #1421
Closed

Add Symbol.toStringTag to promise instance #1277

Strate opened this issue Nov 4, 2016 · 7 comments · Fixed by #1421

Comments

@Strate
Copy link

Strate commented Nov 4, 2016

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.

@benjamingr
Copy link
Collaborator

I don't know how I feel about this. How would users be able to tell native promises apart?

@ronzeidman
Copy link

ronzeidman commented Dec 7, 2016

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]');
}

@torkelrogstad
Copy link

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.

@benjamingr
Copy link
Collaborator

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.

@spion
Copy link
Collaborator

spion commented Jun 12, 2018

They cannot be passed where a native promise is required as an argument due to the missing toStringTag symbol.

@spion
Copy link
Collaborator

spion commented Jun 12, 2018

Theoretically, the .d.ts file could contain it -- however, DT maintainers are reluctant to add something that does not exist (and with good reason):

DefinitelyTyped/DefinitelyTyped#11027 (comment)

@spion
Copy link
Collaborator

spion commented Jun 12, 2018

We should definitely do this, the only questions are:

  • can we make it so that Object.prototype.toString.call(promise) returns the same thing it did before
  • is anyone using the presence of [Symbol.toStringTag] directly to tell native from BB promises apart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants