Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object properties are allowed on const enums #55421

Closed
bgenia opened this issue Aug 17, 2023 · 1 comment · Fixed by #55424
Closed

Object properties are allowed on const enums #55421

bgenia opened this issue Aug 17, 2023 · 1 comment · Fixed by #55424
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@bgenia
Copy link

bgenia commented Aug 17, 2023

🔎 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

@fatcerberus
Copy link

Not a duplicate, but tangentially related to #40740. In both cases there's an inherent design limitation in that TS isn't able to represent (in the type system) an object that doesn't inherit from Object.prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants