Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流-在类的静态中找不到属性_Javascript_Ecmascript 6_Flowtype - Fatal编程技术网

Javascript 流-在类的静态中找不到属性

Javascript 流-在类的静态中找不到属性,javascript,ecmascript-6,flowtype,Javascript,Ecmascript 6,Flowtype,给定一个具有静态属性的类,以及一个通过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
访问该属性的方法:

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对此工作代码不满意?我可以做些什么使其在代码或流配置中满意?

找到了一个解决方案:

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

  static get PI() {
    return 3.14
  }
}
找到了一个解决方案:

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

  static get PI() {
    return 3.14
  }
}

一个解决方案是根本不使其成为静态的,而只是使其成为文件中的一个变量。您可以在没有实现的情况下向类中添加类似
static PI:number
的类型声明吗?一个解决方案是根本不使其成为静态的,而只是使其成为文件中的一个变量。您可以添加类似
static的类型声明吗PI:没有实现的类的编号