Skip to content

Missing use-before-defined error for enums #33204

@asurance

Description

@asurance

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。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions