【发布时间】:2017-06-18 03:46:15
【问题描述】:
在以下代码中,我的clone 调用出现错误:
/* @flow */
class A {
get clone(): this {
return Object.assign(Object.create(this), this)
}
}
class B extends A {}
var b = new B();
var c = b.clone
我收到一个错误:协变属性 clone 与调用方法 assign 时的逆变使用不兼容。
如何注释这个,请纠正我的例子。
【问题讨论】:
-
你真正想要的是
Object.assign(Object.create(Object.getPrototypeOf(this)), this) -
谢谢,但我得到 flowtype 错误:此类型与 this 的预期返回类型不兼容。 See Code example here
标签: javascript flowtype es6-class