Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithApolloClient types client as optional #7899

Closed
billsaysthis opened this issue Mar 25, 2021 · 2 comments
Closed

WithApolloClient types client as optional #7899

billsaysthis opened this issue Mar 25, 2021 · 2 comments

Comments

@billsaysthis
Copy link

billsaysthis commented Mar 25, 2021

Intended outcome:
Trying to migrate to V3 and unlike in V2 the client prop is set as optional, this creates issues in our existing codebase because everywhere I use client is flagged as potentially undefined. I know this is deprecated but for migration purposes I need to use this for the time being.

Actual outcome:
This is a blocker for us, not sure what other actual outcome I can add here.

How to reproduce the issue:
From the types:

export declare type WithApolloClient<P> = P & {
    client?: ApolloClient<any>;
};

Versions
3.3.12

@brainkim
Copy link
Contributor

brainkim commented Mar 25, 2021

@billsaysthis I’m sorry to hear you’re having trouble with types! I’m trying to track down why the client prop was marked as optional.

In the meantime, I typically try to never let anything like TypeScript get in the way of shipping. If you’re not familiar there are a couple of temporary workarounds you could use to fix this problem:

import {ApolloClient} from "@apollo/client";
import type {WithApolloClient} from "@apollo/client/react/hoc";

declare const w: WithApolloClient<{}>;

// option 1: non-null assertion operator 
const client1: ApolloClient = w.client!;

// option 2: as operator
const client2: ApolloClient = w.client as ApolloClient; // or `any`

// option 3: @ts-ignore directive
// @ts-ignore: fix when this issue is resolved https://github.com/apollographql/apollo-client/issues/7899
const client3: ApolloClient = w.client;

I know it’s non-ideal, but if you’re just trying to upgrade, maybe you can do this for now and fix it later?

Potentially related issues:
apollographql/react-apollo#3392
apollographql/react-apollo#3538

@billsaysthis
Copy link
Author

Thanks for the prompt response.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants