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

Export simple type annotations for function-as-a-child arguments #69

Closed
peterszerzo opened this issue Oct 15, 2018 · 5 comments
Closed
Assignees

Comments

@peterszerzo
Copy link
Contributor

peterszerzo commented Oct 15, 2018

Is your feature request related to a problem? Please describe.
Sometimes it is necessary to pass down methods such as refetch and mutate that come from the function-as-a-child arguments of the Get and Mutate components, e.g. child component or a component method at which point they need a type annotation. Currently, this is quite hard to reproduce with the mutate API looking something like this: https://github.com/contiamo/restful-react/blob/master/src/Mutate.tsx#L119.

Describe the solution you'd like
The library should export interfaces for these methods taking the number and configuration of generics as the Get or Mutate components themselves. This would make type annotations straightforward and easy to follow.

@peterszerzo peterszerzo self-assigned this Oct 15, 2018
@TejasQ
Copy link
Contributor

TejasQ commented Oct 16, 2018

Does the self-assignment mean you're making a PR that fixes this? 😄

@peterszerzo
Copy link
Contributor Author

Yes, I got started on it - it turns out it is not that simple because Mutate works off of a union of different props configurations, so the type annotation of the method itself cannot be determined at compile-time. We can bypass this by exporting type annotations for all cases, and doing a manual type annotation in client code where the intent is known. How does that sound to you?

@TejasQ
Copy link
Contributor

TejasQ commented Oct 16, 2018

🤔

Mutate works off of a union of different props configurations, so the type annotation of the method itself cannot be determined at compile-time

I'm having a little trouble grokking this. Sorry, my head was just knee-deep in IdP talk. 😅 I might come back to this later. Or if you could possible rephrase/illustrate with snippets I'd be grateful.

@peterszerzo
Copy link
Contributor Author

The mutate argument in the render props pattern can have the following signatures:

mutate: (body?: string | {}) => Promise<TData>

mutate: (resourceId?: string | {}) => Promise<TData>

and this is based on whether we are working with MutateWithDeleteProps and MutateWithOtherVerbProps, but we won't be able to tell statically which one. Therefor my suggestion was to export both annotations and leave it up to the user to use the one that's relevant to each use-case when this comes up.

@peterszerzo
Copy link
Contributor Author

Oh wow they're actually the same, never mind I didn't say anything :)

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