我有以下代码:
class Table {
get pagination () {
return {
get item () {
return {
log (s : string) {
console.log(s);
}
}
}
}
}
}
class TableWithFirst extends Table {
get pagination () {
return {
...super.pagination,
get first () {
this.item.log("first");
return "first";
}
}
}
}
const t = new TableWithFirst();
t.pagination.first
,这段代码中,我得到了下面的错误:
[ERR]: "Executed JavaScript Failed:"
[ERR]: Cannot read properties of undefined (reading 'log')
如何将first
getter添加到pagination
?将逻辑移到类中是唯一的方法吗?
如果你不需要支持旧版本的浏览器,你可以将编译目标更改为ES2018(或更高版本),这样扩展语法就不会被编译了。
游乐场
关于TestCafe,在这里你可以找到如何定制它的运行器使用的typescript编译器选项(它不会选择标准的tsconfig文件)。