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

typeof enum is weird #3

Open
ljharb opened this issue May 15, 2018 · 1 comment
Open

typeof enum is weird #3

ljharb opened this issue May 15, 2018 · 1 comment

Comments

@ljharb
Copy link

ljharb commented May 15, 2018

For example, in:

enum Colors { Red, Blue, Green }

typeof Colors.Red // `"enum"`, but it's really a string
typeof (0, Colors.Red) // still "enum"?
String.prototype.toString.call(Colors.red) // throws, because it's not a string? "Red", because it's an object boxing a real string with the right internal slots, but then it's not a primitive which means it shouldn't have its own typeof type?

In other words, if enum is a new primitive type, then I think it can't be a "string" or a "number" or a "symbol", it'd have to be something new - probably something that couldn't be coerced casually to those things.

#2, however, might address this.

@rbuckton
Copy link
Owner

If we stick with the enum primitive type, then I imagine String.prototype.toString.call(Colors.red) would throw (assuming enum Colors { Red = "Red", ... }), since its neither a String nor an Object with a [[StringData]] internal slot.

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

No branches or pull requests

2 participants