TypeScript Version: all the ones in playground, latest is v4.1.0-dev20201001
Search Terms:
enum, incorrect type, computed enum, number, string
Code
enum Constants {
hello = "Hello"
}
enum Potato {
// THIS IS CONSIDERED A NUMERIC ENUM!!!!!
h = Constants.hello
}
// Error: Type 'Potato' is not assignable to type 'string'.(2322)
const value: string = Potato.h;
// intellisense shows Potato.h = "Hello", but tsc compiles as though it's a number
console.log(Potato.h.toExponential());
Expected behavior:
Using a string enum member as the computed key in another enum should either be considered a string enum or be not allowed.
Actual behavior:
Potato.h is typed as number despite being assigned to a string. Potato.h.toExponential() passes type checking and throws runtime error.
Playground Link
Related Issues:
https://stackoverflow.com/questions/64145849/how-can-i-pass-an-enum-with-keys-of-another-string-enum-into-a-function-that-a
TypeScript Version: all the ones in playground, latest is v4.1.0-dev20201001
Search Terms:
enum, incorrect type, computed enum, number, string
Code
Expected behavior:
Using a string enum member as the computed key in another enum should either be considered a string enum or be not allowed.
Actual behavior:
Potato.his typed as number despite being assigned to a string.Potato.h.toExponential()passes type checking and throws runtime error.Playground Link
Related Issues:
https://stackoverflow.com/questions/64145849/how-can-i-pass-an-enum-with-keys-of-another-string-enum-into-a-function-that-a