這裏我的問題: 我得到這個錯誤:類型錯誤的打字稿
Uncaught TypeError: Object prototype may only be an Object or null: undefined
export abstract class AbstractLogicExpression {
protected _logicChildExpressions: AbstractLogicExpression[] = Array();
protected _precedence = 0;
protected _parsed = false;
protected _expressionType = "";
protected rightAssociative = false;
public toDNF() {
for (let i = 0; i < this.logicChildExpressions.length; i++) {
let actualLogicExpression: AbstractLogicExpression = this.logicChildExpressions[i];
if (actualLogicExpression._expressionType == "~") {
let logicConjunction = actualLogicExpression.logicChildExpressions[0];
let var1 = logicConjunction.logicChildExpressions[0];
let var2 = logicConjunction.logicChildExpressions[1];
if (logicConjunction._expressionType == "*") {
actualLogicExpression.logicChildExpressions[0] = new LogicOr();
//actualLogicExpression.logicChildExpressions[0].add(new LogicNeg(var1));
//actualLogicExpression.logicChildExpressions[0].add(new LogicNeg(var2));
}
}
}
}
}
我得到這個錯誤,因爲該行的前兩個註釋行:
actualLogicExpression.logicChildExpressions[0] = new LogicOr();
我測試通過評論和取消註釋行,因爲我在錯誤消息中沒有行號。
有人知道我能做什麼嗎? 如果您需要更多的代碼。我可以張貼的東西...
這裏LogicOr的代碼: https://pastebin.com/T28Zjbtb
我猜LogicOr有問題。你能發表該類的定義嗎?也許這是相關的? https://github.com/Microsoft/TypeScript/issues/14734 – dbandstra
你的權利,如果我用空替換LogiOr錯誤消失。但爲什麼? – leet
您是否正確導入它,並確保它正確綁定?在我看來,這個類在運行時不再存在? – dbandstra