TypeScript Version: 3.5.1
Code
class test {
static log() {
console.log(Const.value);
}
}
test.log();
enum Const {
value = 1
}
class test {
static instance = new test();
constructor() {
console.log(Const.value);
}
}
enum Const {
value = 1
}
Expected behavior:
Run with no error
Actual behavior:
Uncaught TypeError: Cannot read property 'value' of undefined
Playground Link:
http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEAuCmFbQN4FgBQ1pLLAlsNCAPYDmAFAJSqbbbAkB2EJI8AdKZQMLNIcAbmBABXeFQDcdaAF9M8jAgHdq0jPCaiAttD4tk6LNGFj40ALzQAjAsxA
http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEAuCmFbQN4FgBQ1pLLAlsNPgHa4nDzQC80J8A7nIrABQCUA3JtsAPZlYAJwCuwWHyEdUPbNH5k+IeADoQfAOasAwgKQqAbmBAj4XWQF9MVjPBIiAttF2CZWaEZNVaARmuYgA
More Info
Use const enum or use enum before class declaration can avoid this problem。
Maybe enum object should be moved ahead of file after complied。
TypeScript Version: 3.5.1
Code
Expected behavior:
Run with no error
Actual behavior:
Uncaught TypeError: Cannot read property 'value' of undefined
Playground Link:
http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEAuCmFbQN4FgBQ1pLLAlsNCAPYDmAFAJSqbbbAkB2EJI8AdKZQMLNIcAbmBABXeFQDcdaAF9M8jAgHdq0jPCaiAttD4tk6LNGFj40ALzQAjAsxA
http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEAuCmFbQN4FgBQ1pLLAlsNPgHa4nDzQC80J8A7nIrABQCUA3JtsAPZlYAJwCuwWHyEdUPbNH5k+IeADoQfAOasAwgKQqAbmBAj4XWQF9MVjPBIiAttF2CZWaEZNVaARmuYgA
More Info
Use const enum or use enum before class declaration can avoid this problem。
Maybe enum object should be moved ahead of file after complied。