-
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
Feature: migration tool to convert a full project from JSDoc to TypeScript strict #19285
Comments
Sounds like a perfect idea for a wider community project that leverages the TypeScript language services and compiler API. Building it into |
👍 We would love to see a separate tool that does this. Typescript may add individual features over time to make it easier, but I think a "js2ts" tool is the right design. |
We have made sure that all our codefix/refactoring logic is in a detachable form the language service API*. so it should be possible to leverage all the refacorings logic to achieve a standalone conversion tool. (*) i am sure we will find bugs once we try to use them in a different context, but these should all be fixable. |
Related is #19255 |
I have idea for another tool (but related) generate type definitions from js code annotated with JSDoc, but type checked with TypeScript. Example puppeteer: they use ES7 + JSDoc + TypeScript as a a checker. Related: puppeteer/puppeteer#1170 |
Looking for #7546 ? |
@mhegazy yes, thank you very much |
Closing this as it has been told as outside TS goals. |
It is out of scope of the TypeScript project, but we like to keep the suggestion active; a community member can pick this one up and provide a tool that accomplish the task. we would be happy to help as needed. |
Closing this issue as TypeScript now knows how to convert jsdoc to types for a whole file at once. |
This issue appear on search engines when you look for that. How can you convert a |
Yeah I would like to be able to do this too - I would like a codemod or similar to be able to transition from this: function add (/** @type {number} */ a, /** @type {number} */ b) { ...to this: function add (a: number, b: number) { ...as well as supporting all other features of JSDoc (eg. I assume such a converter / codemod exists somewhere, but I haven't been able to find it yet... |
If anyone ever finds such codemod, or builds it, please come back here and let us know |
https://www.npmjs.com/package/ts-migrate-plugins |
@whocaresk do you know how well this works? How many different sorts of JSDoc annotations can it convert to TS? cc @edsrzf |
There's also https://github.com/microsoft/ts-fix, which should let you run the jsdoc-to-types codefix on your whole project at once. |
Currently, to stay aligned with native JavaScript, you can migrate a JavaScript project to TypeScript just by switching to
.ts
files and everything should be OK (except if there are real errors).But you're not in
strict
mode, which is what you want if you come to TypeScript.Now that JSDoc is understood by TypeScript, and following #18747, it would help TypeScript adoption a lot to have a tool to refactor a full JavaScript project, correctly commented with JSDoc, to TypeScript (applying #18747 quickfix everywhere).
It could even include the conversion from
.js
to.ts
extension.It would mean we can automatically migrate from a JS project to real TypeScript (aka
strict
mode).The text was updated successfully, but these errors were encountered: