-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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.
Related Issues:
thomastay, yuriy-razvalinov-mck, Ajiharan, captain-yossarian, giovannipds and 8 morejcalzR4YM3
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue