如何在apollo graphql中输入React Component

时间:2017-11-18 16:03:55

标签: flowtype react-apollo

我正在尝试使用flow和apollo graphql正确键入react组件。我一直收到流错误消息。我正在使用react-apollo 2.0.1和流量0.53.1

// @flow
/**
*
* CompanyName
*
*/

import React from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import type { OperationComponent, ChildProps } from 'react-apollo';

type Company = {
  id: string,
  name: string,
};

type Response = {
  company: Company,
};

type Props = {
  className: ?string,
};


class CompanyName extends React.Component<ChildProps<Props, Response>> {
  render() {
    return (
      <span className={this.props.className}>
        {!!this.props.data.company && this.props.data.company.name}
      </span>
    );
  }
}

const query = gql`
  query {
    company {
      id
      name
    }
  }
`;

const withCompanyName: OperationComponent<Response, Props> = graphql(query);

export default withCompanyName(CompanyName); // this line gives a flow error

我在最后一行代码中遇到错误,说明该类型不兼容。其他一切都正确验证。

错误消息是:CompanyName(类类型:CompanyName)此类型与StatelessComponent不兼容(union:type of polymorphic type:type StatelessComponent | class type:type application of identifier React$Component

如果我将其更改为无状态功能组件,我能够使其正常工作,但我需要将其用于类组件。

更新 这是我的.flowconfig

[ignore]

[include]

[libs]

[options]
module.name_mapper='.*\(.gql\)' -> 'empty/object'

我正在使用空包来防止gql导入导致流错误。

0 个答案:

没有答案