Mav*_*ick 34 javascript visual-studio asp.net-mvc-4 typescript
所以我在控制台中遇到了上述错误.它是由_super传递给__extends(在生成中.js)时未定义引起的.
这是一些可用于重现错误的测试代码:
//This is the entirety of the file Test.ts
module Test {
export class Test1 {
public Name: string;
public Number: number;
constructor() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后在一个单独的文件中,我有一个继承自那个的类:
/// <reference path="Test.ts" />
module Test {
export class Test2 extends Test1 {
constructor() {
super();
}
}
}
Run Code Online (Sandbox Code Playgroud)
本<reference path...不应该需要(而不是),但我添加它,看它是否帮助了(事实并非如此).
文件包含在正确的顺序(Test.ts然后Test2.ts)通过BundleConfig(运行有或没有优化没有任何影响).
我可能是一个巨大的菜鸟,但我没有丝毫的线索我搞砸了什么.我在网上找到的这个问题的所有其他实例都来自使用命令行编译器将多个Typescript文件合并为一个文件的人.我正在使用捆绑器来做到这一点,但即使我没有将它们组合起来,我也会遇到完全相同的问题.
请帮助我,我的智慧结束了!
根据要求,这里是编译的javascript:Test.js:
//This is the entirety of the file Test.ts
var Test;
(function (Test) {
var Test1 = (function () {
function Test1() {
}
return Test1;
})();
Test.Test1 = Test1;
})(Test || (Test = {}));
//# sourceMappingURL=Test.js.map
Run Code Online (Sandbox Code Playgroud)
Test2.js:
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;
d.prototype = new __();
};
/// <reference path="Test.ts" />
var Test;
(function (Test) {
var Test2 = (function (_super) {
__extends(Test2, _super);
function Test2() {
_super.call(this);
}
return Test2;
})(Test.Test1);
Test.Test2 = Test2;
})(Test || (Test = {}));
//# sourceMappingURL=Test2.js.map
Run Code Online (Sandbox Code Playgroud)
Rya*_*ugh 25
发生这种情况的可能原因:
BundleConfig以正确顺序连接文件的四重检查.到目前为止,这是该错误的最常见原因.export指令Test.ts.这将导致文件成为外部模块,并且Test1将不再可见.如果做不到这一点,您应该将发出的JavaScript发布到问题中,以便我们可以诊断导致问题的原因.
sup*_*jos 18
今天发生了这个错误.不确定什么是OP场景,但在我的团队的情况下,我们有:
dependencies.ts)Uncaught TypeError: Cannot read property 'prototype' of undefined__extends另一个类的最后一行的内部函数,在另一个文件中(比如说client.ts),将它们作为依赖项导入在代码中:
// dependencies.ts
import { Injectable } from 'angular2/core';
@Injectable()
export class LocalStorageService extends BaseStorageService {
constructor() {
super(localStorage);
}
}
class BaseStorageService {
constructor(private storage: Storage) {}
// ...
}
Run Code Online (Sandbox Code Playgroud)
和:
// client.ts
import { Injectable } from 'angular2/core';
import { LocalStorageService } from './dependencies';
@Injectable()
export class AuthStorageService {
constructor(private permanentStorage: LocalStorageService) { }
// ...
} // <-- call stack pointed here with inner '__extends' function
Run Code Online (Sandbox Code Playgroud)
通过在派生类之前定义基类来解决问题.快速搜索和阅读后,这似乎与已知(和未解决的?)TypeScript问题有关,例如#21和#1842.
HTH
| 归档时间: |
|
| 查看次数: |
29240 次 |
| 最近记录: |