能否使用Flow注释类型内联标注函数的隐式this参数?
关于Flow隐式
this参数的注释类型标注问题 可行,你可以通过Flow的注释类型语法对隐式this参数进行内联标注,以此消除该错误提示。
两种实现方式:
方式一:在函数签名后标注
直接在函数定义后添加类型注释,明确指定this的类型与函数返回值:// @flow function printValue() /*: (this: { value: string }) => void */ { console.log(this.value); }方式二:函数内联标注
在函数内部第一行通过注释直接标注this的类型:// @flow function printNumber() { (this: { num: number }); console.log(this.num); }
你遇到的错误提示:
Missing an annotation on implicit
thisparameter of function.
内容的提问来源于stack exchange,提问作者Olle Härstedt
相关产品推荐
相关产品推荐

