如何使用FlowType继承类?

时间:2018-09-15 07:56:19

标签: javascript reactjs react-native flowtype

使用React(ReactNative)。

想继承Component类,但在这种情况下会发生流错误的麻烦。

TryFlow

/* @flow */

import React, { Component } from 'react';
import { Text, View } from 'react-native';

type commonProps ={
  actions: Object,
};

type someProps = commonProps & {
  someNumber: number,
};

class CustomComponent extends Component<commonProps> {
  static defaultProps: {};
  props: commonProps;
}

class MyComponent extends CustomComponent {
  props: someProps;

  render() {
    return (
      <Text>{this.props.someNumber}</Text>
    );
  }
}

该怎么办?

1 个答案:

答案 0 :(得分:0)

我想您应该为类设置类型注释。像这样:

class CustomComponent<commonProps> extends Component<Props, State> {
   static defaultProps: {};
   props: commonProps;
}