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

Specification for Enum's needs to use 'SignedInteger' in constant productions, not NumericLiteral #538

Closed
mhegazy opened this issue Aug 26, 2014 · 2 comments
Assignees
Labels
Spec Issues related to the TypeScript language specification

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Aug 26, 2014

Courtsey of @CyrusNajmabadi

The spec currently lists this in the grammar productions for an Enum:

ConstantEnumMemberSection:
PropertyName = NumericLiteral
PropertyName = NumericLiteral , ConstantEnumMembers

This is slightly incorrect (and different from a previous version of the spec).

Specifically, previous versions used:

PropertyName = SignedInteger

The approach with "SignedInteger" is likely more correct. NumericLiteral doesn't allow for things like "-1". With the grammar productions as they exist in the latest version of the spec "-1" would be thought of as a computed expression. i.e. the negation expression of the literal '1'.

This is important if we consider "-1" as a constant or not in an enum. Right now we do. But according to the spec, it would not be.

Also, with "PropertyName = NumericLiteral" we can do "Foo = 3.14159" and that would be considered a constant. That's likely not at all what we want

@mhegazy mhegazy added the Spec label Aug 26, 2014
@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 24, 2015
@mhegazy mhegazy added this to the TypeScript 1.6 milestone Mar 24, 2015
@jbondc
Copy link
Contributor

jbondc commented May 10, 2015

I'm confused by this, is it a breaking change? Prefer NumericLiteral... that's more closely aligned with JavaScript / Number.

A signedInteger enum should be declared as ~:

enum<int32> a {
  a, // 0
  b, = 1.1 // error, initializer must be a constant expression of type 'int32'
  c, = -1, // ok
  d, // 1
}

@mhegazy mhegazy removed the Bug A bug in TypeScript label May 27, 2015
@ahejlsberg
Copy link
Member

No longer an issue. Closing.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

3 participants