Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization

后端 未结 5 2105
别那么骄傲
别那么骄傲 2020-12-10 10:44

I\'m having the following TypeScript class

export class Vehicule extends TrackableEntity {
  vehiculeId: number;
  constructor() {
    super();
    return s         


        
5条回答
  •  [愿得一人]
    2020-12-10 11:14

    You're probably running into this Angular issue: https://github.com/angular/angular-cli/issues/15077.

    From that issue:

    Hi, is there a reason why you need emitDecoratorMetadata to be true?

    This TypeScript option has a fundamental design limitation with ES2015+ code and is best avoided when targeting such output. As such this is an issue with TypeScript itself and not Angular.

    Angular 8+ no longer requires the option. It was also previously only required for JIT mode which is typically only used in development.

    The solution is to set "emitDecoratorMetadata": false in your tsconfig.json file.

    Side note: I must say, given that previous versions of the Angular CLI automatically added emitDecoratorMetadata: true, and there's no reason I can see why a dev should know that emitDecoratorMetadata should now be false, it's pretty horrible that the Angular team basically said "this isn't our problem" and closed the issue without action. This could have been easily "fixed" by adding some better documentation (as pointed out by someone in the linked issue).

提交回复
热议问题