創建一個Angular2應用程序時,在第一個類的構造函數中調用另一個類的構造函數時,我遇到了以下問題。Typescript class.default不是構造函數
頭等艙代碼
import {SecondClass} from './second-class'
export class FirstClass {
someVar:string;
secondClass:SecondClass;
constructor(firstClass?: FirstClass) {
this.someVar='test';
this.secondClass= new SecondClass();
}
}
二等代碼:
export class SecondClass {
someOtherVar:string;
constructor(secondClass?:SecondClass) {
this.someOtherVar='test';
}
}
能給我的錯誤:原來的異常:類型錯誤:second_class_1.default不是構造函數的
內容。/second-class
System.register([], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var SecondClass;
return {
setters:[],
execute: function() {
SecondClass = (function() {
function SecondClass(secondClass) {
this.someOtherVar='test';
}
return SecondClass;
}());
exports_1("SecondClass", SecondClass);
}
}
});
//# sourceMappingURL=second-class.js.map
這是來自Typescript編譯器的編譯輸出
發佈內容。 – dfsq
'default'是一個[javascript保留字](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords)。 – Mottie
SecondClass可能出現循環錯誤 – randominstanceOfLivingThing