-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use JSDoc to check and generate TypeScript typings #5
Use JSDoc to check and generate TypeScript typings #5
Conversation
acb9470
to
963c1c2
Compare
I think this is a great idea! unified stuff used to have JSDocs way back when! |
Another drawback is that the code side increases a lot. The code I just linked had 49 lines of code, the file with comments is 139 lines. That’s almost tripling the size. If we pull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense! The barrier for me when adding types to an existing package for the first time was figuring out imports, name spaces, and other specific TypeScript things I did not encounter before. This switches to a more 'natural' type specification and leaves the details to the compiler.
However, adding comments to test files to also test types feels a bit weird to me. I’m not sure how extensive the generated test.d.ts
file is out-of-the-box and what our standards are for type tests. But I feel that part might make more sense explicitly in its own file. The downside is that it brings in extra config files, though we already have those in the existing approach.
Good point, updating RFC to include this.
Another RFC for this is in the works.
Good point, I may add a dedicated section to the RFC for this.
I see your point, and I'm open to the idea.
Another alternative would be to make test file a |
Co-authored-by: Titus Wormer <tituswormer@gmail.com>
Hmm.. I think using JSDoc would work for simple projects. But for unified ecosystem, I'm a bit worrying. I've checked how interfaces works in JSDoc but I couldn't find proper ways to importing and exporting those interfaces. I think this is quite important for unified because most of packages of unified are using Also we might lose some keywords like How can we tackle those problems if we adopt JSDoc? |
Thanks for the feedback @Rokt33r! 🙇
This is a concern I initially shared. Documentation for these is located at https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#import-types and https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#typedef-callback-and-param
While I would generally prefer to stay away from both of these types. |
Thanks for clarification. I've read the article from typescript just now. It looks good to me. I also want to try to adopt it. 👍 |
for anyone reading along, @ChristianMurphy and I have recently tried this in xdm, works pretty well, although indeed a bit verbose: https://github.com/wooorm/xdm/blob/964eb45052e7fe130788540521b8ec81a1138fea/lib/core.js#L13 |
Why not use |
I think these are my main three reasons on why I prefer jsdoc ts over
|
It is possible.
In the meantime, JSDoc based annotations allow authors and maintainers that prefer vanilla javascript to continue doing so, and also generate typings which keep in sync with the code. |
Another possible value point for JSDoc, it could be used to generate the readme documentation, for example something like: https://github.com/jsdoc2md/jsdoc-to-markdown |
JSDoc based types has been rolled out to most of unified as part of unifiedjs/unified#121 |
Rendered version: https://github.com/unifiedjs/rfcs/blob/963c1c20de118a2e9e60e249e56a5f18c573c8fa/text/0000-generate-typings-from-jsdoc.md
This would also be made easier by #4
Blog post by another project (and a
remark
adopter) who have also taken this approach https://dev.to/open-wc/generating-typescript-definition-files-from-javascript-5bp2Example of what this would look like in unified vfile/vfile-message#8