Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fail to start typescript compiled file

I have converted big JS project to typescript (as I C# programmer) using in PhantomJs. The problem is interpreter (phantomjs) fails while executing this js file.

D:\My\phantomjs-1.9.7-windows\phantomjs.exe --load-images=false --ssl-protocol=any --web-security=no --cookies-file=cookies C:\Users\alex\Projects\robot\bo.js
TypeError: 'undefined' is not an object (evaluating 'b.prototype')

the code is:

var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
    function __() { this.constructor = d; }
    __.prototype = b.prototype; // <<< here
    d.prototype = new __();
};

So. I think the problem is somewhat related to inheritance. Have any one encountered this problem? Any help is appreciated. Thanks.

like image 322
Alexey Kulikov Avatar asked Nov 27 '14 14:11

Alexey Kulikov


1 Answers

The most common cause of this error is that you are loading the files in the wrong order... for example...

File A

class ExampleClass {
    someMethod() {
        alert('Hello World');
    }
}

File B

class ExampleSubClass extends ExampleClass {

}

If you were to load File B before File A, you would get the exact error you are describing. (This includes forgetting to load File A or loading File A after File B).

Fixes

If you are combining all of your files into a single file (and you are probably using a _references.ts file) make sure the references are in the right order.

/// <reference path="file-a.ts" />
/// <reference path="file-b.ts" />

If you are using script tags, it is the similar fix (making sure you are using .js extensions and checking the order of loading)...

<script src="file-a.js"></script>
<script src="file-b.js"></script>
like image 174
Fenton Avatar answered Oct 22 '22 04:10

Fenton