属性'me'在类型"{}".ts(2339) 上不存在



所以我在props.me.id上得到了上面提到的错误。如何解决此问题?

组件/订单清单.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

您尚未为props指定类型。

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

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

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

最新更新