Skip to content

Const enum initializers reject numeric const variable references #3620

Closed

Description

@nickna
const source = 4;
const enum E { A = source, B }
console.log(E.B);

TypeScript 6.0.3 accepts this with --ignoreConfig --strict --target ES2022 --noEmit. Its emitted JavaScript prints 5. SharpTS with --no-tsconfig --strict --noEmit reports Expression type 'Variable' is not allowed in const enum initializer.

#3604 tracks the ordinary enum case. This case also needs the const enum's compile-time values in the interpreter and compiler.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions