⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.1.6#code/MYewdgzgLgBApmArgWxgFTtAok1BvAKBmJgEEYBeGARgBoiSAhSmAWmoIF8CDRIQANnAB0AkAHMAFA2JQAngAc4IAGYwAylABOASzBSM2XMNIBKeiRjylq9Jig4UJ4VBCbd+yaYLfe4CIIiYlIyVorKau56BvaOyMKM5qHWEXZGTowubtrRXj5AA
💻 Code
const enum TestEnum {
A = 1,
B = -1
}
// "string", "string"
console.log(
typeof String(TestEnum.A),
typeof TestEnum.A.toString()
)
// "string", "number"
console.log(
typeof String(TestEnum.B),
typeof TestEnum.B.toString()
)
🙁 Actual behavior
Constant enums which use negative numbers will return type of number when .toString() is called.
🙂 Expected behavior
A string type should be returned
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.1.6#code/MYewdgzgLgBApmArgWxgFTtAok1BvAKBmJgEEYBeGARgBoiSAhSmAWmoIF8CDRIQANnAB0AkAHMAFA2JQAngAc4IAGYwAylABOASzBSM2XMNIBKeiRjylq9Jig4UJ4VBCbd+yaYLfe4CIIiYlIyVorKau56BvaOyMKM5qHWEXZGTowubtrRXj5AA
💻 Code
🙁 Actual behavior
Constant enums which use negative numbers will return type of
numberwhen.toString()is called.🙂 Expected behavior
A
stringtype should be returned