【发布时间】:2019-12-19 16:44:12
【问题描述】:
我正在像这样设置 Apollo Client。
const defaultOptions = {
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'ignore',
},
query: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
},
mutate: {
errorPolicy: 'all',
},
};
return new ApolloClient({
link: ApolloLink.from([authLink, errorLink, webSocketOrHttpLink]),
defaultOptions, // Typescript don't like this.
queryDeduplication: true,
});
Typescript 给出了这个错误:
Type '{ watchQuery: { fetchPolicy: string; errorPolicy: string; }; query: { fetchPolicy: string; errorPolicy: string; }; mutate: { errorPolicy: string; }; }' is not assignable to type 'DefaultOptions'.ts(2322)
ApolloClient.d.ts(23, 5): The expected type comes from property 'defaultOptions' which is declared here on type 'ApolloClientOptions<NormalizedCacheObject>'
根据文档,this 应该是这样做的。
如何使用正确的类型构造defaultOptions?
【问题讨论】:
-
试试 defaultOptions: defaultOptions
-
@PranayRana 没有区别。 ????
-
嗨,您为 fetchPolicy 传递了错误的值,请检查我的答案
标签: typescript apollo react-apollo apollo-client