Closed
Description
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms:
const enum initializer
ts2474
Code
// lib.ts
const enum STATIC_KEYS {
ZERO,
ONE,
TWO,
LAST
}
export const STARTING_NUMBER = STATIC_KEYS.LAST;
// consumer.ts
const enum MORE_STATIC_KEYS {
ONE = STARTING_NUMBER, // error TS2474; STATIC_KEYS.LAST works as expected
TWO,
THREE,
}
Expected behavior:
Code compiles with MORE_STATIC_KEYS.ONE === STATIC_KEYS.LAST
.
Actual behavior:
error TS2474: In 'const' enum declarations member initializer must be constant expression.
TS recognizes that STARTING_NUMBER
has the type STATIC_KEYS.LAST
, but doesn't consider it a 'constant expression.'
If this is expected behavior, clarity in the error message would be appreciated.
Playground Link: link
Related Issues:
Multiple discussions about merging/intersecting of const enums, of which the above is my attempted workaround.