Feature: migration tool to convert a full project from JSDoc to TypeScript strict #19285
Copy link
Copy link
Closed
Closed
Copy link
Labels
Community ToolingThis might be better handled by tooling from the community instead of built into TypeScriptThis might be better handled by tooling from the community instead of built into TypeScriptNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Community ToolingThis might be better handled by tooling from the community instead of built into TypeScriptThis might be better handled by tooling from the community instead of built into TypeScriptNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Activity
kitsonk commentedon Oct 18, 2017
Sounds like a perfect idea for a wider community project that leverages the TypeScript language services and compiler API. Building it into
tscdoesn't feel in line with the design goals IMO.sandersn commentedon Oct 18, 2017
👍 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.
mhegazy commentedon Oct 18, 2017
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.
DanielRosenwasser commentedon Oct 18, 2017
Related is #19255
stereobooster commentedon Oct 28, 2017
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
mhegazy commentedon Oct 30, 2017
Looking for #7546 ?
stereobooster commentedon Oct 30, 2017
Mohamed Hegazy (@mhegazy) yes, thank you very much
cyrilletuzi commentedon Feb 8, 2018
Closing this as it has been told as outside TS goals.
mhegazy commentedon Feb 8, 2018
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.
cyrilletuzi commentedon Aug 28, 2020
Closing this issue as TypeScript now knows how to convert jsdoc to types for a whole file at once.
fungiboletus commentedon Nov 21, 2020
This issue appear on search engines when you look for that.
How can you convert a
.jswith JSDoc comments to a.tsfile ? I cannot find how in the documentation. It's recommended to rename the file and fix it manually.karlhorky commentedon Jan 6, 2021
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:
...to this:
...as well as supporting all other features of JSDoc (eg.
@typedef-> type alias,@template-> generics, etc).I assume such a converter / codemod exists somewhere, but I haven't been able to find it yet...
danielo515 commentedon Aug 7, 2021
If anyone ever finds such codemod, or builds it, please come back here and let us know
whocaresk commentedon Aug 11, 2021
https://www.npmjs.com/package/ts-migrate-plugins
this is probably what you're looking for
karlhorky commentedon Aug 11, 2021
Anton Filatov (@whocaresk) do you know how well this works? How many different sorts of JSDoc annotations can it convert to TS?
cc Evan Shaw (@edsrzf)
sandersn commentedon Aug 12, 2021
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.