Open
Description
π Search Terms
enum constant minus-zero -0
π Version & Regression Information
- This is the behavior in every version I tried ( 3.3.3 - 5.9.0-dev.20250702 )
β― Playground Link
π» Code
enum X {
Literal = -0
}
console.log(Object.is(X.Literal, -0));
π Actual behavior
Generates
"use strict";
var X;
(function (X) {
X[X["Literal"] = 0] = "Literal";
})(X || (X = {}));
console.log(Object.is(X.Literal, -0));
π Expected behavior
Either Generates an enum member with a value of -0, or an error.
"use strict";
var X;
(function (X) {
X[X["Literal"] = -0] = "Literal";
})(X || (X = {}));
console.log(Object.is(X.Literal, -0));
Additional information about the issue
The reverse mappings in this case might be problematic since both 0 and -1 stringify to 0. That said, TypeScript is already ok with multiple entries that have the same value overwriting the reverse mapping (and even the enum entries themselves in the case of infinites and NaN) so I think it would be fine. That issue though is why it might be desirable to error.
Metadata
Metadata
Assignees
Labels
No labels