Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Mutation function causes typescript error 2453 (not a valid type argument) #769

Closed
skosch opened this issue Jun 12, 2017 · 4 comments
Closed

Comments

@skosch
Copy link

skosch commented Jun 12, 2017

I'm applying Apollo's functionality on my component as follows:

export const InternalSettings = compose(
  graphql(internalSettingsQuery),
  graphql(updateInternalSettingsMutation, {
    props: ({mutate}) => ({
      updateMutation: (changes: any) => mutate({
        variables: {
          input: {internalSettings: changes, clientMutationId: '0'},
        }
      })
    })
  }),
)(LoadingSpinnerWrapper(InternalSettingsComponent))

This works fine as a JS file, but compiling with TypeScript results in an error:

    TS2453: The type argument for type parameter 'A' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
  Type argument candidate 'CompositeComponent<{ data?: QueryProps; mutate?: MutationFunc<{}>; }>' is not a valid type argument because it is not a supertype of candidate 'ComponentClass<{}>'.
    Type 'ComponentClass<{}>' is not assignable to type 'StatelessComponent<{ data?: QueryProps; mutate?: MutationFunc<{}>; }>'.
      Types of property 'propTypes' are incompatible.
        Type 'ValidationMap<{}>' is not assignable to type 'ValidationMap<{ data?: QueryProps; mutate?: MutationFunc<{}>; }>'.
          Property 'data' is missing in type 'ValidationMap<{}>'.

Do I need to explicitly type things in my mutation query setup? If yes, how, and is this documented somewhere? Thanks!

Version

  • apollo-client@1.4.2
  • react-apollo@1.4.2
@stale
Copy link

stale bot commented Jul 5, 2017

This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if not further activity occurs. Thank you for your contributions to React Apollo!

@settings settings bot removed the wontfix label Jul 8, 2017
@estaub
Copy link

estaub commented Jul 10, 2017

I'm no expert, but it looks to me like the design of the react-apollo types prevents use of nested mutation and query on a component without some fakery. The definition of the TResult generic parameter comes into conflict from the component having both a query and mutation.

A workaround, in my case, was to remove the mutation from the component's props generic parameter, and then invoke the mutation via this.props['mutation_name']. Any port in a storm...

If anyone can demonstrate successful clean use (as opposed to my hack) of nested query and mutation, please show!

Wild guess: a fix might be to use different generic parameters for TResult for mutation and query.

@stale
Copy link

stale bot commented Jul 31, 2017

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

@stale
Copy link

stale bot commented Sep 5, 2017

This issue has been automatically closed because it has not had recent activity after being marked as no recent activyt. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!

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

No branches or pull requests

2 participants