Skip to content

Specific enum value not comparable with number in 5.0Β #52701

Closed
@jakebailey

Description

@jakebailey

Bug Report

πŸ”Ž Search Terms

operator cannot be applied enum number comparison

πŸ•— Version & Regression Information

  • This changed between versions 4.9 and 5.0

⏯ Playground Link

Playground Link

πŸ’» Code

const enum Constants {
    DefaultName = "foo",
    DefaultTimeout = 1000,
    MaxItems = 25,
}

declare var someValue: number

if (someValue > Constants.MaxItems) {
    someValue = Constants.MaxItems;
}

πŸ™ Actual behavior

Operator '>' cannot be applied to types 'number' and 'Constants'.(2365)

Removing the string-ish value from Constants stops the error.

πŸ™‚ Expected behavior

No error; even though Constants shouldn't be comparable thanks to #52048, this seems like it should work because it's only referencing a specific value.

/cc @Andarist @ahejlsberg

Metadata

Metadata

Assignees

Labels

Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions