Service class inheritance and file order

I have a service (class in TypeScript) app/resources/GeneralResource.ts and other services in the app/resources/ folder. I want to inherit all my resources from GeneralResources .

All files (classes) that go after the GeneralResource.ts file in alphabetical order work fine. But all files (classes) that go to GeneralResource.ts have a runtime error.

Here is an example class:

 export class DefectReasonResource extends GeneralResource implements IDefectReasonResource { static $inject = ['$q', '$http', 'baseUrl']; constructor(public $q:ng.IQService, public $http:ng.IHttpService, public baseUrl:string) { super($q, $http); } // ... 

This class compiles fine:

 var app; (function (app) { var common; (function (common) { var DefectReasonResource = (function (_super) { __extends(DefectReasonResource, _super); function DefectReasonResource($q, $http, baseUrl) { _super.call(this, $q, $http); this.$q = $q; this.$http = $http; this.baseUrl = baseUrl; } DefectReasonResource.$inject = ['$q', '$http', 'baseUrl']; return DefectReasonResource; })(common.GeneralResource); common.DefectReasonResource = DefectReasonResource; angular.module('myApp').service('defectReasonResource', DefectReasonResource); })(common = app.common || (app.common = {})); })(app || (app = {})); 

But when I open the file, I have an error in the browser:

Uncaught TypeError: Cannot read the 'prototype' property from undefined

I just want to emphasize that I do not have this problem with all classes declared after GeneralResource .

I think it's best to remove inheritance and add GeneralResource to all my services. But I wonder if the inheritance solution can be fixed?

+5
source share
1 answer

You did not specify how your installation looks. But I came across this when I used (TypeScript) internal modules. You just need to make sure you remember to add a review:

 ///<reference path="relative/path/to/GeneralResource.ts" /> 

in your app/resources/serviceName.ts . The purpose of the comment is to ensure that the order of the files (or their contents) is correct in the final app.js file (if you use the --outFile flag).

+1
source

Source: https://habr.com/ru/post/1239728/


All Articles