microsoft / microsoft/TypeScript
Enum value `1 / 0` incorrectly transformed if there is `Infinity` declared in scope
Open
Nobody has claimed this yet.
Bug
Domain: enum
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
infinity enum variable let shadow
🕗 Version & Regression Information
Every version I tested
⏯ Playground Link
Playground link with relevant code
💻 Code
{
let Infinity = 3;
enum A {
X = 1 / 0
}
console.log(A.X)
}
🙁 Actual behavior
{
let Infinity = 3;
let A;
(function (A) {
A[A["X"] = Infinity] = "X";
})(A || (A = {}));
console.log(A.X);
}
and logs 3
🙂 Expected behavior
It should log the result of 1 / 0, which is Infinity.
Somewhat related to https://github.com/microsoft/TypeScript/issues/54981.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground and the enum example, then trace the compiler's enum emission and constant-expression handling for 1 / 0 when Infinity is shadowed. Done means the emitted JavaScript evaluates A.X as the result of 1 / 0 rather than the local Infinity variable, with regression coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100