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

Why is There No Typescript Documentation? #974

Open
jwalkerinterpres opened this issue Aug 30, 2024 · 1 comment
Open

Why is There No Typescript Documentation? #974

jwalkerinterpres opened this issue Aug 30, 2024 · 1 comment
Labels
question Further information is requested

Comments

@jwalkerinterpres
Copy link

This library clearly supports TypeScript, because I see types mentioned in the commit messages, eg.

fix(types): move types to optional peer dependencies

However, the word "type" doesn't even appear in your documentation or readme file. To be fair, types don't exactly require a ton of docs, but it'd be nice to at least mention how they're supposed to be used.

For instance:

 // Error: Property 'foo' does not exist on type 'RenderHookResult<MyHook<object>, unknown>'.ts
 const { foo } = renderHook(hook);

// Error: Expected 2-5 type arguments, but got 1.ts(2558)
const { foo } = renderHook<{ foo: any }>(hook);

So it seems renderHooks expects 2-5 type arguments ... surely you could spare a few lines in the docs to tell us what those arguments should be?

@jwalkerinterpres jwalkerinterpres added the question Further information is requested label Aug 30, 2024
@jwalkerinterpres
Copy link
Author

jwalkerinterpres commented Aug 30, 2024

P.S. Based on https://github.com/testing-library/react-hooks-testing-library/blob/main/src/types/react.ts it looks like the function actually takes two type arguments:

  • the TProps, which appears to be the type of the arguments of the hook function being tests?
  • the TResult, which appears to be the type of what the hook being tested returns?

Even a single line of documentation:

This function takes two type parameters, the type of the hook's input and the type of its output.

would help clarify things.

(Also, the error message above mentioned "2-5" type arguments ... maybe another sentence could cover what those args are?)

EDIT: Actually I think I was looking at the wrong place (the perils of trying to make your own docs from unknown source code 😄). It looks like the real type to look at is the RenderHookResult in https://github.com/testing-library/react-hooks-testing-library/blob/main/src/types/index.ts ... which also seems to take "props" and result.

It also takes a third TRenderer (although I'm unclear on what this is), so that (sort of) explains the 3rd type parameter (I'm still unclear on #4/#5).

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

No branches or pull requests

1 participant