Skip to content

Const enum expression in Ambient enum declaration behaves differently between spec and compiler #2790

Closed
@yuit

Description

@yuit

According to spec:

An expression is considered a constant enum expression if it is one of the following:
....
*** An identifier or property access that denotes a previously declared member in the same constant enum declaration.
....

In the Ambient Enum Declaration,

In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions.

However, compiler reports an error for the following code:

declare enum E {
    a = 10,
    b = a,  // Ambient enum elements can only have integer literal initializers.
    e = 10 << 2 * 8,  // error as well
}

This is contradict to what it means to be constant enum expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions