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 · 0 comments
Open

Unmasked type cause the type error in MockedResponse type #12271

DmitryMasley opened this issue Jan 14, 2025 · 0 comments

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant