-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc typing <-> inline type annotation conversion #48982
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
Comments
Basically the same as #19285. |
@fatcerberus That's JS-to-TS. The other point is TS-to-JS (with JSDocs), |
If I understand this, what the OP primarily wants is... export function foo(a: number, b: number): number {
return a + b;
} ...to be compiled to... /**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function foo(a, b) {
return a + b;
} I don't think that's a duplicate of either. Basically, people want the JS output to be both (a) runnable on its own and (b) contains all the necessary type information. |
I’m pretty sure there’s an existing issue about converting TS types to JSDoc when compiling, but I couldn’t find it. |
See #10 |
I swear I did a comprehensive search but didn't see that one, thanks! |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
⭐ Suggestion
.ts files transpiled to .js should have an option to move the typing to JSDoc-style comments, like https://www.npmjs.com/package/ts-to-jsdoc . Intelligently built, this could also allow the reverse - diligently JSDoc'd .js files to be "upgraded" to .ts with the typical in-line type annotations instead of the JSDoc, which could help a lot with TypeScript adoption.
🔍 Search Terms
jsdoc transpiling transpiler transpilation typing type_annotations
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example
Admittedly the possible JSDoc'd .js -> inline-annotated .ts that could be informed by this change would be much more productive for most purposes, but I strongly believe that a deep enough understanding of the JSDoc vs. .ts typing connection would be useful for both.
💻 Use Cases
What do you want to use this for?
The Bitburner community extensively uses TypeScript via a VS Code extension and template to write scripts for the game in much more tightly typed TypeScript. However, the game itself only supports Javascript (technically, a very close sibling called Netscript 2), so the TypeScript written this way has to be transpiled to .js before being sent to the game, thus losing all type readability in-game. If the transpilation added JSDoc, though, it would continue to be very readable in-game due to the JSDoc support the game has.
What shortcomings exist with current approaches?
Obviously, you could just use removeComments = false and put the JSDoc typing into the .ts before transpiling, but that would result in double-typing and be ugly and unwieldy. The converse (JSDoc .js to inline-annotated .ts) doesn't even seem to be automatically possible atm, which is a shame because for the most part the supported type names are exactly the same.
What workarounds are you using in the meantime?
As mentioned, there's https://www.npmjs.com/package/ts-to-jsdoc, but it only seems to support single files at a time, which, as the TypeScript docs mention, can miss out on typing information from other files. Also, I am using a gulp pipeline to do the transpile for https://www.npmjs.com/package/gulp-preserve-typescript-whitespace, and I don't understand how/if I could integrate https://www.npmjs.com/package/ts-to-jsdoc with https://www.npmjs.com/package/gulp-typescript.
If anybody has additional workarounds, I'm very interested in hearing about them!
The text was updated successfully, but these errors were encountered: