Skip to content

TS 2535 when using const enum values derived from other const enum values #35875

Closed
@dead-claudia

Description

@dead-claudia

TypeScript Version: 3.7.2

Search Terms: 2535 const enum

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
const enum Foo { Value = 0x01 }
const enum Bar { Value = 0x02 }
const enum Baz { Value = Foo.Value | Bar.Value }
type Test = Baz.Value

const foo: Foo.Value = Foo.Value
const bar: Bar.Value = Bar.Value
const baz: Baz.Value = Baz.Value

Expected behavior: It to type-check without errors

Actual behavior: "Enum type 'Baz' has members with initializers that are not literals. (2535)" on both the type alias and the baz type, referencing Baz.Value in the type position.

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=8&pc=33#code/MYewdgzgLgBApmArgWxgMRCGBvGA1AQwBtE4YBeGABgA8qBGGAXwChRJYEUYAhAgJxz5ipCtToAmZm3DR4SVHwBeQwiTKUMIAHRrRAH14DdIsqygBPAA5kAKnDmVlJ9SxkcYAM0wAudJhdRTQC9OHc5ACMBPz5+QI0jONDw2CilGIIleLFnUKA

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issueIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions