在Flow中,如何在Component上注释“this.keyword”(不是Props或State)?

时间:2017-03-27 23:45:41

标签: flowtype

type Props = {
  loading: boolean,
  posts: PostNode,
  loadMoreEntries: () => PostFeed,
  showActionSheetWithOptions: () => Function,
  deletePost: (postId: string) => PostNode,
}

type State = {
  selectedIndex: number,
}

class Discussions extends Component {
  props: Props;
  state: State;

  constructor(props: Props) {
    super(props);

    this.keyword = '';

    this.state = {
      selectedIndex: 1,
    };
  }
...

在这种情况下,我指的是构造函数中的this.keyword,Component上的属性既不是道具也不是状态。

1 个答案:

答案 0 :(得分:1)

props: Props;
state: State;

stateprops的注释。您可以使用keyword以相同的方式注释keyword: string;