Why Does This Typescript Output “[Class] is not a constructor.”?

后端 未结 12 1379
清歌不尽
清歌不尽 2021-01-17 07:55

I\'m working in typescript 1.5 in visual studio. I have a main class called app.ts, and another called FizzBuzzManager.ts. I can\'t figure out what is wrong with this code,

12条回答
  •  梦谈多话
    2021-01-17 08:42

    This error message means that [Class] is not initialized by the time a call to its constructor is made.

    Unlike functions, classes are not “hoisted” to the top of the scope they are declared in. Whenever code uses a class that is declared later (i.e. down below in the file), this error appears.

    Solution: reorganize your code so that call sites for a class appear below that class' definition in the source code.

提交回复
热议问题