Skip to content

Specific enum value not comparable with number in 5.0 #52701

Description

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

constenumConstants{DefaultName="foo",DefaultTimeout=1000,MaxItems=25,}declarevarsomeValue: numberif(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 Mateusz Burzyński (@Andarist)Anders Hejlsberg (@ahejlsberg)

Metadata

Metadata

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