相关疑难解决方法(0)

如何正确输入 Apollo 客户端 defaultOptions?

我正在像这样设置 Apollo 客户端。

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,
});
Run Code Online (Sandbox Code Playgroud)

打字稿给出了这个错误:

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 …
Run Code Online (Sandbox Code Playgroud)

typescript apollo react-apollo apollo-client

3
推荐指数
1
解决办法
6210
查看次数

标签 统计

apollo ×1

apollo-client ×1

react-apollo ×1

typescript ×1