-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Support 'Promote JSDoc comment to type annotation' #2916
Comments
I like the idea; but I thik we should break this into pieces:
|
I created closure-ts that is d.ts generator from JSDoc typings. |
I'm unsure whether we would want to do something like give an error on certain JSDoc comments in TypeScript. It seems plausible that people would still want those comments for some other system in their build pipeline but perhaps not. |
@danquirk that is why i was saying 1. make it a warning not an error, and 2. emit type information in jsdoc. so it is an error to include the type in a .ts file jsdoc, and the compiler will put in the correct type when it writes out the jsdoc. |
I adapted @mhegazy's list to a task list in the original comment. @CyrusNajmabadi can check off anything he's already worked on. I think the first item has been taken care of. |
Regarding the first step, it appears https://github.com/jsdoc2md/jsdoc-parse already provides some of the facilities for parsing JSDoc, though it additionally gets type information from declaration signatures. Perhaps rather than re-writing the tool for our own purposes we could contribute and add a PR for an API? EDIT: using that tool would likely be inefficient as it requires a second scan of a sourcefile for the tool and it's unclear how to extend it for live-editing. oops. |
That would be so great to see adoption within the community. 😄 |
Lots of work to do here. @aozgaa is doing some of it; we'd take PRs on other parts. This can be an area of incremental improvement |
Most of the work outlined here has been covered by #4789 |
We should consider the feasibility of a simple editor command where existing JSDoc comments are automatically converted to TypeScript type annotations. This could be a massive benefit for easing migration from JavaScript to TypeScript both in terms of saving pain fixing 'errors' (ie places that need type annotations) and being able to immediately leverage TypeScript's biggest value prop.
In addition, this could be a great way to improve the .d.ts generation process. Imagine picking up a new JS library that doesn't have a .d.ts but is well documented with JSDoc comments. Despite the lack of a .d.ts on DefinitelyTyped you could simply use this new command to promote the JSDoc comments to type annotations, then run the file through tsc --declaration and in almost no time have a high quality .d.ts.
Edit by @DanielRosenwasser:
.js
files.d.ts
from a.js
file.js
files.The text was updated successfully, but these errors were encountered: