流量 - 在类的静力学中找不到的属性

时间:2017-08-15 20:38:09

标签: javascript ecmascript-6 flowtype

给定一个具有静态属性的类,以及通过this.constructor访问该属性的方法:

class Matematica {
  reset() {
    this.constante = this.constructor.PI;
  }
}

Matematica.PI = 3.14

Flow无法找到静态属性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对这个工作代码感到不满意?我该怎么做才能让它在代码或流程配置中变得快乐?

1 个答案:

答案 0 :(得分:0)

找到解决方案:

class Matematica {
  reset() {
    this.constante = this.constructor.PI;
  }

  static get PI() {
    return 3.14
  }
}