Skip to content

Object properties are allowed on const enums #55421

@bgenia

Description

@bgenia

🔎 Search Terms

const enum Object properties constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf

🕗 Version & Regression Information

  • This seems like a bug
  • This is the behavior in every version I tried (3.3-5.3 nightly)

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.1.6#code/MYewdgzgLgBApmArgWxgITgIwE4EMYDeAvgLABQ5A9JTAIIA29MIAZjFABZwRwyjIAHAJb1euMABMYOOLgDWMbIjBQhyOOVCQQogHT0QAcwAUGHLl1boS4FBDYAlJvAQdcfUdNY8ujrggA8gDuYAAK2CACcNhQAJ5OZFZuHiZmPkIQ4SB2cVEBLAlJegap3hYCEVExsQCSEACiSOp4mKKFLsklXua6dgAyIMC4ogDKUNhCYIbt2sWeaRZ2YxNTM65zpT0AbsOIcPkJVDQAKlw8MBIgMGDZfCCCIrzG-vAAHlG2cBIJ1OhlvdwoEc-uYANoAciggPBAF1gVZYMAAIwwAC8ILw5CAA

💻 Code

const enum Bebra {}

// All of these compile and break runtime
console.log(Bebra.constructor)
console.log(Bebra.hasOwnProperty)
console.log(Bebra.isPrototypeOf)
console.log(Bebra.propertyIsEnumerable)
console.log(Bebra.toLocaleString)
console.log(Bebra.toString)
console.log(Bebra.valueOf)

// These do not compile (as expected)
Bebra.test
Bebra['test']
const c1 = Bebra

🙁 Actual behavior

TS Allows usage of Object methods on a const enum, which breaks runtime because const enums are ment to be fully erased.

🙂 Expected behavior

TS should disallow such things as it does with other properties.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions