Reactjs 如何为Apollo'定义道具界面;那是什么?

Reactjs 如何为Apollo'定义道具界面;那是什么?,reactjs,typescript,react-apollo,Reactjs,Typescript,React Apollo,我正试图使用Apollo的React-HOC获取数据并将数据传递给我的组件,但我得到一个错误: Argument of type 'typeof BrandList' is not assignable to parameter of type 'CompositeComponent<{ data?: QueryProps | undefined; mutate?: MutationFunc<{}> | undefined; }>'. Type 'typeof Bran

我正试图使用Apollo的React-HOC获取数据并将数据传递给我的组件,但我得到一个错误:

Argument of type 'typeof BrandList' is not assignable to parameter of type 
'CompositeComponent<{ data?: QueryProps | undefined; mutate?: MutationFunc<{}> | undefined; }>'.
Type 'typeof BrandList' is not assignable to type 'StatelessComponent<{ data?: 
QueryProps | undefined; mutate?: MutationFunc<{}> | undefined; }>'.
Type 'typeof BrandList' provides no match for the signature '(props: { data?: 
QueryProps | undefined; mutate?: MutationFunc<{}> | undefined; } & { children?: ReactNode; }, context?: any): ReactElement<any>'.
这消除了错误,但现在当我尝试将组件作为

<div>
    <BrandList />
</div>

我遇到以下错误:

Type '{}' is not assignable to type 'Readonly<IProps>'.
Property 'data' is missing in type '{}'.
类型“{}”不能分配给类型“Readonly”。
类型“{}”中缺少属性“data”。

好的,我已经解决了这个问题。。我不得不添加另一个道具界面

interface IExternalProps {
  id: string
}

interface IProps extends IExternalProps {
  data: IData
}

export default graphql<any, IExternalProps}>(BrandsQuery)(BrandList)
接口IExternalProps{
id:字符串
}
接口IProps扩展了IExternalProps{
资料来源:IData
}
导出默认图形QL(BrandsQuery)(BrandList)

基本上,
IExternalProps
是组件从外部期望的道具接口,即在JSX中实际使用组件时,
IProps
是通过GraphQL查询(HOC)接收道具的接口。此界面必须扩展
IExternalProps
,然后才有机会实际键入检查它。

你的意思是
graphql
HOC期望通过
IExternalProps
暴露的道具吗?@LiauJianJie是的。请注意,在标记
any
的地方,阿波罗文档将阿波罗有效载荷的类型放在:
Type '{}' is not assignable to type 'Readonly<IProps>'.
Property 'data' is missing in type '{}'.
interface IExternalProps {
  id: string
}

interface IProps extends IExternalProps {
  data: IData
}

export default graphql<any, IExternalProps}>(BrandsQuery)(BrandList)