属性“ me”在类型“ {}”上不存在。ts(2339)

时间:2020-09-24 16:05:28

标签: typescript graphql apollo-client

所以我在props.me.id上收到上述错误。我该如何解决?

components / OrderList.tsx

const USER_ORDERS_QUERY = gql`
  query USER_ORDERS_QUERY($userId: String) {
    orders(where: { user: { equals: $userId } }, orderBy: { createdAt: desc }) {
      id
      total
      createdAt
      items {
        id
        title
        price
        description
        mainDescription
        quantity
        image
      }
      user
    }
  }
`;

const userOrdersQuery = graphql(
  USER_ORDERS_QUERY,
  {
    options: props => ({
      variables: {
        userId: props.me.id,
      },
      fetchPolicy: 'cache-and-network',
      pollInterval: 300
    })
  }
);

const OrderList = props => {
  const { me, user_ip, user_Agent, url, urlReferer, client, data: { orders, loading: loadingQuery, error: errorQuery, startPolling, stopPolling, subscribeToMore }} = props;

}

const ItemWithApollo = withApollo(OrderList)
export default memo(userOrdersQuery(ItemWithApollo));

我的部分回购可以在这里找到:https://github.com/TheoMer/next_apollo

1 个答案:

答案 0 :(得分:1)

您尚未为props指定类型。

在许多情况下,TypeScript无法自动推断参数的类型,通常,您需要手动指定它们(如果可能)或使用props: any(如果不能,但是可以,但要避免!)。

在这种情况下,您可以仅指定props.me.id属性,如下所示:

options: (props: { me: { id: string } }) => ({
  // ...