【发布时间】:2018-04-24 01:06:50
【问题描述】:
将 TKO / Knockout.js 转译回 ES3 或 ES5 以兼容 IE9, tko.binding.if/src/ifNotWith.js这里遇到错误:
class ConditionalBindingHandler extends AsyncBindingHandler {
...
get shouldDisplayIf () { return !!unwrap(this.value) }
...
}
export class UnlessBindingHandler extends ConditionalBindingHandler {
get shouldDisplayIf () { return !super.shouldDisplayIf }
}
在其上运行 Typescript 后出现此错误,因为 Typescript 将 super.shouldDisplayIf 更改为 super.prototype.shouldDisplayIf,这会更改 this 引用。
它应该做什么(获取,但设置类似)是这样的:
p = Object.getOwnPropertyDescriptor(super, 'shouldDisplayIf')
return 'get' in p ? p.get.call(this) || p.value
...但事实并非如此。这是 Typescript 的一个已知问题,还是我遗漏了什么?
我能找到的唯一相关问题是:https://github.com/Microsoft/TypeScript/issues/338
【问题讨论】:
-
确实 Microsoft/TypeScript#338 看起来像相关问题。您需要在这里回答什么吗?
-
@jcalz 谢谢。相关答案表明我弄错了或遗漏了有关解决方法的一些信息,但是看起来您正在确认我的研究。如果您有信心,请随时发布答案,我会将其标记为正确。
-
@BrianM.Hunt 链接不起作用(到 github 仓库)
-
@Cody - 谢谢,已修复
标签: typescript