最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - fail to start typescript compiled file - Stack Overflow

programmeradmin8浏览0评论

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.

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.

Share Improve this question edited Nov 27, 2014 at 15:27 Sarath Subramanian 21.4k12 gold badges89 silver badges95 bronze badges asked Nov 27, 2014 at 14:29 Alexey KulikovAlexey Kulikov 1,1471 gold badge14 silver badges38 bronze badges 1
  • does typescriptlang/Playground piles your code? or maybe a peace of code? It is also possible to generate source maps for typescript and inspect buggy part of typescript in devtools in chrome – Ivan Demchenko Commented Nov 27, 2014 at 15:35
Add a ment  | 

1 Answer 1

Reset to default 12

The most mon 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 bining 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>
发布评论

评论列表(0)

  1. 暂无评论