Failed to start typescript compiled file

I converted a large JS project to typescript (as a C # programmer) using in PhantomJs. The problem is that the 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:

 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. Has anyone encountered this issue? Any help is appreciated. Thanks.

+5
source share
1 answer

The most common cause of this error is that you are uploading 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 download File B to File A , you will get the exact error that you are describing. (This includes forgetting to download File A or download File A after File B ).

difficult

If you merge all your files into a single file (and you are probably using the _references.ts file), make sure the links are in the correct order.

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

If you use script tags, this is a similar fix (make sure you use the .js extensions and check the loading order) ...

 <script src="file-a.js"></script> <script src="file-b.js"></script> 
+12
source

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


All Articles