由于两条注释行之前的行,我收到此错误:
actualLogicExpression.logicChildExpressions[0] = new LogicOr();
我通过注释测试它并取消注释行,因为我在错误消息中没有得到行号.
有人知道我能做什么吗?如果您需要更多代码.我可以张贴一些东西......
这里是LogicOr的代码:https://pastebin.com/T28Zjbtb
1> 小智..:
除此之外,循环依赖的实际问题是因为在使用之前未加载的资源之一.如果您的资源无序加载,您也会收到此错误.
考虑使用gulp编译的这个示例:
// File Parent.ts
export class Parent {
public prop: string = "prop";
}
//File Child.ts
export class Child extends Parent {
public prop2: string = "prop2";
}
和gulp编译
gulp.task('compile-js', function () {
return gulp.src(['code/Child.js', 'code/Parent.js'])
.pipe(sourcemaps.init())
.pipe(concat('app.bundle.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('app/build'));
});
输出文件app.bundle.js将出错"Uncaught TypeError:Object prototype可能只是一个Object或null:undefined",因为生成的代码将首先执行Child类的创建(它依赖于Parent类)在加载父类之前.
如果您查看生成的Javascript,您将获得:
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.cOnstructor= d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Child = /** @class */ (function (_super) {
__extends(Child, _super);
function Child() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.prop2 = "prop2";
return _this;
}
return Child;
}(Parent));
var Parent = /** @class */ (function () {
function Parent() {
this.prop = "prop";
}
return Parent;
}());
当你运行这个时,你会得到:
未捕获的TypeError:对象原型可能只是一个Object或null:setPrototypeOf()中未定义
要解决此问题,只需更改gulp文件中的资源顺序或用于准备或加载页面的Javascript的任何方法.
return gulp.src(['code/Parent.js', 'code/Child.js'])
有很多方法可以解决这个问题,这只是一个帮助您了解问题以及如何解决问题的示例.无论你找到什么方法来解决这个问题,最后,错误就是要求Javascript引擎做一些你在执行时尚未给出指令的东西.
希望这会有所帮助,干杯
2> basarat..:
你在这一行得到一个错误:
actualLogicExpression.logicChildExpressions [0] = new LogicOr();
错误消息是
未捕获的TypeError:对象原型可能只是一个Object或null:undefined
一旦熟悉了类及其工作原理(https://basarat.gitbooks.io/typescript/docs/classes.html),就很容易理解.
错误意味着new LogicOr
失败,因为LogicOr
正在扩展的东西undefined
.简单的例子:
let Bar;
class Foo extends Bar { } // Uncaught TypeError: Object prototype may only be an Object or null: undefined
更多
修复bug LogicOr
及其继承链.
但是LogicOr从AbstractLogicExpression正确扩展。Typescript是否无法处理循环依赖项?
“ Typescript是否无法处理循环依赖关系?”这是commonjs的局限性。建议删除它们。为了进行分析,我使用https://alm-tools.gitbooks.io/alm/content/features/dependency.html
我解决了循环依赖问题,现在可以工作了