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

Include usage documentations in JSDoc #34

Closed
mohsen1 opened this issue Nov 6, 2018 · 12 comments
Closed

Include usage documentations in JSDoc #34

mohsen1 opened this issue Nov 6, 2018 · 12 comments

Comments

@mohsen1
Copy link

mohsen1 commented Nov 6, 2018

All types have nice usage docs. Would be nice to have them in JSDoc to show up in text editors.

@piotrwitek
Copy link
Owner

piotrwitek commented Nov 8, 2018

That's interesting idea. What are the best practices to implement that, can you link to some examples?

The main concern is maintainability of these JSDoc comments, like for example when we update usage examples they should stay up to date.

@mohsen1
Copy link
Author

mohsen1 commented Nov 9, 2018

You probably want to use the JSDoc as the source of truth and then use tools like tsdoc to generate your README and/or website from it.

@IssueHuntBot
Copy link

@issuehuntfest has funded $20.00 to this issue. See it on IssueHunt

@rahgurung
Copy link
Contributor

@mohsen1 @piotrwitek I would like to take this, can you get me started please.

@piotrwitek
Copy link
Owner

piotrwitek commented Feb 21, 2019

@gurungrahul2 That's awesome!

  1. First step would be to copy all the examples from README to the source files like this (note I removed import and moved "Expect" on top):
/**
 * SetIntersection (same as Extract)
 * @desc Set intersection of given union types `A` and `B`
 * @example
 * ```
 * // Expect: "2" | "3"
 * type ResultSet = SetIntersection<'1' | '2' | '3', '2' | '3' | '4'>;
 * // Expect: () => void
 * type ResultSetMixed = SetIntersection<string | number | (() => void), Function>;
 * ```
 */
export type SetIntersection<A, B> = A extends B ? A : never;
  1. Second step is to parse source files to generate a markdown based docs static website. One way is to use a full documentation generator to generate a website from source files (I'm open to suggestions if you can find something but I guess TypeScript support will be required, maybe this: https://dotnet.github.io/docfx/).
    Another way would be to use simple JSDoc => Markdown (like jsdoc2md) converter and then use it as a page in a markdown docs generator like Docsaurus.

Additional finds:

Now notice that this issue is only about (1).
For (2) we have a separate issue that you're free to pick-up later if you want: #30

Let me know what you think!

@rahgurung
Copy link
Contributor

@piotrwitek I am working on 1, and I will take 2 after it, I will ping you if I have queries, on it.

@piotrwitek
Copy link
Owner

@gurungrahul2 that's cool! Let me know when you'll be approaching (2), I'll try to help as much as I can.

@mohsen1
Copy link
Author

mohsen1 commented Feb 21, 2019

note that the JSDoc markdown doesn't support triple backtick code blocks. You must indent code blocks.

@piotrwitek
Copy link
Owner

@mohsen1 could you be more specific about what are you referring to? is it @example directive or what?

@mohsen1
Copy link
Author

mohsen1 commented Feb 21, 2019

JSDoc is not that well specified but in most tools I have used the triple backtick was not working. It's not specific to a single directive like @example.

@piotrwitek
Copy link
Owner

Thanks @mohsen1, I got it now.

rahgurung added a commit to rahgurung/utility-types that referenced this issue Feb 22, 2019
piotrwitek pushed a commit that referenced this issue Feb 23, 2019
* #34 - added usage document in JSDoc

* added spacing and corrected expected comments
@IssueHuntBot
Copy link

@piotrwitek has rewarded $14.00 to @gurungrahul2. See it on IssueHunt

  • 💰 Total deposit: $20.00
  • 🎉 Repository reward(20%): $4.00
  • 🔧 Service fee(10%): $2.00

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

No branches or pull requests

4 participants