如何使以下代码与 flow js 注释一起使用?使用 Object.create()
How to make the following code work with flow js annotations? Using Object.create()
在以下代码中,我的 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
.
调用中的逆变使用不兼容
如何注释,请指正我的示例。
我现在让它工作了(通过转换为任何):
/* @flow */
class A {
get clone(): this {
return Object.assign((Object.create(this): any), this)
}
}
class B extends A {}
var b = new B()
var c = b.clone
在以下代码中,我的 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
.
如何注释,请指正我的示例。
我现在让它工作了(通过转换为任何):
/* @flow */
class A {
get clone(): this {
return Object.assign((Object.create(this): any), this)
}
}
class B extends A {}
var b = new B()
var c = b.clone