类型'IntrinsicAttributes&RefAttributes <Component <{},any,any >>'上不存在属性'item'.ts(2322)

时间:2020-09-27 11:09:35

标签: reactjs typescript next.js apollo

“反应”:“ ^ 16.12.0”,
“ typescript”:“ ^ 4.0.3”,
“ next”:“ ^ 9.4.4”

因此,打字稿正在道具prop <Item item={item} key={item.id} urlReferer={urlReferer} />上发出上述错误,该错误在子组件中定义。我该如何解决?

ItemListItems.tsx

enter image description here

Item.tsx

enter image description here

我的部分回购:https://github.com/TheoMer/next_apollo

1 个答案:

答案 0 :(得分:1)

已解决:Apollo HOC要求指定InputProps以反映组件中消耗的道具:

component / Item.tsx

type InputProps = {
  item: Item;
  urlReferer: string;
};

type ChildProps = ChildDataProps<InputProps, Response, {}>

const userQuery = graphql<InputProps, Response, {}, ChildProps>(
  CURRENT_USER_QUERY,
  {
    options: { 
      fetchPolicy: 'cache-and-network',
      pollInterval: 300
    },
  }
);

interface Props {
  data?: any;
  item?: Item;
  urlReferer?: string;
}

const ItemComp: FC<Props> = ({ item, urlReferer, data: { me, error, stopPolling, subscribeToMore }}) => {