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:没有实现的类的编号
?