relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
540 stars 56 forks source link

Split Mutate<T> into MutateWithVariables<T> and Mutate<T> for variables typesafety #139

Closed andrehsu closed 3 years ago

andrehsu commented 3 years ago

Currently, if you call useMutate with no variables argument, and use the resulting function without specifying variables, you can a runtime error. By using method overloading and by having a separate MutateWithVariables type, the invariant check can be enforced at compile-time.

Also, since the ...config spread is the last argument, the variables in userConfig is always going to override the variables specified in mutate(config)

I can submit a PR if this is a good idea.

morrys commented 3 years ago

hi @andrehsu, sounds like a nice idea 👍 In PR, at the moment, I would not remove the invariant.

morrys commented 3 years ago

Hi @andrehsu, today (soon) release version 4.0.0-rc.4 with your PR, I would like to have your feedback as over the weekend I intend to officially release version 4.0.0 👍