简体   繁体   English

无法启动typescript编译文件

[英]fail to start typescript compiled file

I have converted big JS project to typescript (as IC# programmer) using in PhantomJs. 我已经使用PhantomJs将大型JS项目转换为打字稿(作为IC#程序员)。 The problem is interpreter (phantomjs) fails while executing this js file. 问题是解释器(phantomjs)在执行此js文件时失败。

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. 谢谢。

The most common cause of this error is that you are loading the files in the wrong order... for example... 导致此错误的最常见原因是您以错误的顺序加载文件...例如......

File A 档案A.

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

File B 档案B.

class ExampleSubClass extends ExampleClass {

}

If you were to load File B before File A , you would get the exact error you are describing. 如果您在File A之前加载File B ,您将得到您描述的确切错误。 (This includes forgetting to load File A or loading File A after File B ). (这包括忘记加载File A或在File B之后加载File A )。

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. 如果要将所有文件合并到一个文件中(并且可能正在使用_references.ts文件),请确保引用的顺序正确。

/// <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)... 如果您正在使用脚本标记,则是类似的修复(确保您使用.js扩展并检查加载顺序)...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM