Skip to content

Symbols couldn't convert properly with String() method #6272

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

Closed
greybax opened this issue Dec 28, 2015 · 10 comments
Closed

Symbols couldn't convert properly with String() method #6272

greybax opened this issue Dec 28, 2015 · 10 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@greybax
Copy link

greybax commented Dec 28, 2015

The next statement should return true:

return String(Symbol("foo")) === "Symbol(foo)";
@weswigham
Copy link
Member

This statement is always false - the lefthand side of the equality is not a string primitive, but rather a string object - string objects are only checked by reference equality. Since the right hand side is not a string object (its a string primitive), the two are never equal. This isn't a typescript thing - this is normal JS behavior.

@oleg-py
Copy link

oleg-py commented Dec 28, 2015

@weswigham in JS when you call String(obj) without new, you get a primitive string, same as using obj+''

@johnfn
Copy link

johnfn commented Dec 28, 2015

@weswigham Typing that command into the Javascript console on Chrome (with the experimental Javascript flag on) returns true for me.

@saschanaz
Copy link
Contributor

The same is true on Edge and Firefox.

@weswigham
Copy link
Member

Op, sorry, I was mistaken - totally though I saw new. Though, as it turns out I'd be wrong anyway - calling new String on a symbol errors in chrome. In any case, TS doesn't do anything to polyfill symbols for you - wouldn't this be on CoreJS or whatever else you're using to polyfill them? I'm not sure there's anything TS-related here.

@DanielRosenwasser
Copy link
Member

I believe that this either depends on your JS runtime or your polyfill, so this isn't TypeScript-specific.

@DanielRosenwasser DanielRosenwasser added the External Relates to another program, environment, or user action which we cannot control. label Dec 28, 2015
@greybax
Copy link
Author

greybax commented Dec 29, 2015

@DanielRosenwasser this feature one of the required for full support of Symbols in TypeScript.
This issue also mentioned in compat-table/es6
q

@kitsonk
Copy link
Contributor

kitsonk commented Dec 29, 2015

@greybax but if you notice, it is not something that is down emittable to ES5. All the transpilers don't (cannot) support it, because it depends on the runtime engine behaving different in ES6.

@DanielRosenwasser
Copy link
Member

@kitsonk is correct. Babel achieves this here by bundling core.js. We could also bundle core.js to achieve some of the runtime polyfills, but we'd prefer to avoid adding a dependency if possible and let users opt in to that on their own.

@greybax
Copy link
Author

greybax commented Dec 30, 2015

ok

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

7 participants