Typescript中的TypeError [英] TypeError in Typescript
问题描述
这是我的问题:我收到此错误:
Here my problem: I get this error:
未捕获的TypeError:对象原型只能是Object或为null:未定义
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));
}
}
}
}
}
由于出现两条注释行之前的行,导致出现此错误:
I get this error because of the line before the two commented lines:
actualLogicExpression.logicChildExpressions[0] = new LogicOr();
我通过注释并取消注释行来对其进行测试,因为错误消息中没有行号.
I tested it by comment and uncomment the lines, because I get no line number in the error message.
有人知道我能做什么吗?如果您需要更多代码.我可以发布一些东西...
Does someone know what I can do? If you need a little more code. I can post something...
以下是LogicOr的代码: https://pastebin.com/T28Zjbtb
Here the code of LogicOr: https://pastebin.com/T28Zjbtb
推荐答案
在此行出现错误:
actualLogicExpression.logicChildExpressions [0] =新的LogicOr();
actualLogicExpression.logicChildExpressions[0] = new LogicOr();
错误消息是
未捕获的TypeError:对象原型只能是一个对象或为null:未定义
Uncaught TypeError: Object prototype may only be an Object or null: undefined
一旦您熟悉了类及其工作方式,就很容易理解( https://basarat.gitbooks.io/typescript/docs/classes.html ).
It is very easy to understand once you are familiar with Classes and how they work (https://basarat.gitbooks.io/typescript/docs/classes.html).
该错误表示 new LogicOr
失败,因为 LogicOr
正在扩展 undefined
.简单示例:
The error means that new LogicOr
is failing because LogicOr
is extending something that is undefined
. Simple example:
let Bar;
class Foo extends Bar { } // Uncaught TypeError: Object prototype may only be an Object or null: undefined
更多
修复 LogicOr
中的错误及其继承链.
这篇关于Typescript中的TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!