Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service class inheritance and files order

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

All files (classes) that are going after GeneralResource.ts file alphabetically are working fine. But all files (classes) that are going before GeneralResource.ts have a execution-time 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 compile 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 property 'prototype' of undefined

I just want to underline that I don't have this problem with all classes that are declared after GeneralResource.

I think it will be better to remove inheritance and inject GeneralResource to all my services. But I am wondering it is possible to fix inheritance solution ?

like image 230
ceth Avatar asked Nov 08 '22 22:11

ceth


1 Answers

You did not elaborate how your setup looks like. But I encountered this when I used (TypeScript) internal modules. You just have to make sure that you don't forget to add reference comment:

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

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

like image 168
Martin Vseticka Avatar answered Nov 15 '22 06:11

Martin Vseticka