Skip to content

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

Closed
@mhegazy

Description

@mhegazy

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

Metadata

Metadata

Assignees

Labels

SpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions