Closed
Description
Search Terms: Object.values
Code
enum Role {
Admin = 'ADMIN',
Results = 'RESULTS',
Finish = 'FINISH',
Config = 'CONFIG'
}
Object.values(Role).forEach(role => {
console.log(typeof role); // prints 'string' four times
});
Object.values(Role).includes('hello'); // errors at build time
Expected behavior: Object.values(EnumType)
at build time should be returning an array of the same type as the values of the EnumType
.
Actual behavior: Object.values(EnumType).includes('enumValueType')
errors out with
error TS2345: Argument of type '"enumValueType"' is not assignable to parameter of type 'EnumType'.
It appears as though, at build time, Object.values(EnumType)
is parsed as returning an array of EnumType
s.
Error first encountered on Typescript 3.6.2
. Still present as of typescript@next
.
Playground Link: Playground link. Playground does not appear to be correctly using ES2017 and Typescript 3.6.2/3.7.0 are not available.