gpt4 book ai didi

javascript - React @flow 避免重复类型

转载 作者:行者123 更新时间:2023-12-03 00:56:39 25 4
gpt4 key购买 nike

我将 Flow 与 create-react-app 一起使用。有时很容易使用 this.someFlagconstructor(props) 中设置一些标志,但 @flow 对我大喊大叫。临时解决方案是对 this 使用 any 类型。像这样:(this:any).timerID = null;我真的不喜欢它,因为我必须在任何地方使用它,并且代码变得一团糟。实在是不太舒服。我可以以某种方式为当前组件定义 this: any 这样我就不会每次都重复它吗?

最佳答案

你可以很容易地解决这个问题:

class MyComponent extends Component {
myThing: number;

constructor() {
super();
this.myThing = 1;
}

render() {
return <div>my component</div>
}
}

您只需要在类上定义一个类型。

关于javascript - React @flow 避免重复类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52800839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com