【发布时间】:2017-08-17 23:05:37
【问题描述】:
给定一个具有静态属性的类,以及通过this.constructor 访问该属性的方法:
class Matematica {
reset() {
this.constante = this.constructor.PI;
}
}
Matematica.PI = 3.14
流找不到静态属性PI:
xx: this.constructor.PI;
^^ property `PI`. Property not found in
xx: this.constructor.PI;
^^^^ statics of Matematica
xx: Matematica.PI = {
^^ property `PI`. Property not found in
xx: Matematica.PI = {
^^^^^^^^^^ statics of Matematica
为什么 Flow 对这个工作代码不满意,我可以做些什么来让它在代码或流程配置中满意?
【问题讨论】:
-
一种解决方案是根本不让它成为静态的,而让它成为文件中的一个变量。
-
你能在没有实现的情况下向类添加像
static PI: number这样的类型声明吗?
标签: javascript ecmascript-6 flowtype