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

Unmasked type cause the type error in MockedResponse type #12271

Open
DmitryMasley opened this issue Jan 14, 2025 · 3 comments
Open

Unmasked type cause the type error in MockedResponse type #12271

DmitryMasley opened this issue Jan 14, 2025 · 3 comments
Labels
🏓 awaiting-team-response requires input from the apollo team ⛑ TypeScript

Comments

@DmitryMasley
Copy link

Issue Description

I experience the typescript error in @apollo/client v3.12.5 and v3.12.4 when using MockedProvider or MockedResponse type.

          Type 'Unmasked<sub-TData>' is not assignable to type 'Unmasked<super-TData>'.
            Type 'sub-TData | (sub-TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<sub-TData>>> : sub-TData)' is not assignable to type 'Unmasked<super-TData>'.
              Type 'sub-TData' is not assignable to type 'Unmasked<super-TData>'.
                Type 'super-TData' is not assignable to type 'Unmasked<super-TData>'.

11 export interface MockedResponse<out TData = Record<string, any>, out TVariables = Record<string, any>> {

The origin of the error appears to be here

In the source code it is suppressed but in the installed package there is no ignore statement

export interface MockedResponse<out TData = Record<string, any>, out TVariables = Record<string, any>> {
    request: GraphQLRequest<TVariables>;
    maxUsageCount?: number;
    result?: FetchResult<Unmasked<TData>> | ResultFunction<FetchResult<Unmasked<TData>>, TVariables>;
    error?: Error;
    delay?: number;
    variableMatcher?: VariableMatcher<TVariables>;
    newData?: ResultFunction<FetchResult<Unmasked<TData>>, TVariables>;
}

It seems the error can be fixed if out TData is changed to in out TData. I think it is related to branches in the Unmasked type.

Link to Reproduction

https://codesandbox.io/p/devbox/admiring-newton-94hmcs

Reproduction Steps

  • Fork the repo
  • npm i && npm run type-check

@apollo/client version

3.12.5

@jerelmiller jerelmiller added ⛑ TypeScript 🏓 awaiting-team-response requires input from the apollo team labels Jan 22, 2025
@msakrejda
Copy link

I'm still hitting this in 3.13.1. @DmitryMasley, did you find a workaround?

@msakrejda
Copy link

If anyone else runs into this, for now, I've downgraded to 3.11.8 which I think is the last version that does not have this issue.

@rjdestigter
Copy link

Running into this as well in 3.11.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏓 awaiting-team-response requires input from the apollo team ⛑ TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants