简体   繁体   中英

TypeScript AMD module inheritance not working

I've got a bunch of TypeScript files which use extends inheritance. Example:

export class AdminModule extends ModuleBase {
    constructor(moduleData: IModuleData) {
         super(moduleData);
    }
}

They are built with the following tsconfig.json :

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "amd",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "alwaysStrict": true,
    "sourceMap": false,
    "target": "es5",
    "typeRoots": [
      "Typings/**/*"
    ]
  },
  "include": [
    "App/**/*"
  ]
}

The compiler includes this script to all files which inherit something.

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
    extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return extendStatics(d, b);
}
return function (d, b) {
    extendStatics(d, b);
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();  

Now I'm trying to load everything with requirejs, but I get the following error at the line extendStatics(d, b); .

TypeError: Object.setPrototypeOf: expected an object or null, got undefined

Looking at the stack trace, it seems that the base class has not been loaded and is undefined. What am I doing wrong?

I finally found it - it simply was a circular reference causing that error. See: https://requirejs.org/docs/api.html#circular

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM