Skip to content

Feature: migration tool to convert a full project from JSDoc to TypeScript strict #19285

Closed

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).

Activity

  1. kitsonk commented on Oct 18, 2017

    @kitsonk
    Contributor

    Sounds like a perfect idea for a wider community project that leverages the TypeScript language services and compiler API. Building it into tsc doesn't feel in line with the design goals IMO.

  2. sandersn commented on Oct 18, 2017

    @sandersn
    Member

    👍 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.

  3. added
    SuggestionAn idea for TypeScript
    Community ToolingThis might be better handled by tooling from the community instead of built into TypeScript
    on Oct 18, 2017
  4. mhegazy commented on Oct 18, 2017

    @mhegazy
    Contributor

    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.

  5. DanielRosenwasser commented on Oct 18, 2017

    @DanielRosenwasser
    Member

    Related is #19255

  6. stereobooster commented on Oct 28, 2017

    @stereobooster

    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

  7. mhegazy commented on Oct 30, 2017

    @mhegazy
    Contributor

    I have idea for another tool (but related) generate type definitions from js code annotated with JSDoc, but type checked with TypeScript.

    Looking for #7546 ?

  8. stereobooster commented on Oct 30, 2017

    @stereobooster

    Mohamed Hegazy (@mhegazy) yes, thank you very much

  9. cyrilletuzi commented on Feb 8, 2018

    @cyrilletuzi
    Author

    Closing this as it has been told as outside TS goals.

  10. mhegazy commented on Feb 8, 2018

    @mhegazy
    Contributor

    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.

  11. added
    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.
    on Nov 6, 2018
  12. cyrilletuzi commented on Aug 28, 2020

    @cyrilletuzi
    Author

    Closing this issue as TypeScript now knows how to convert jsdoc to types for a whole file at once.

  13. fungiboletus commented on Nov 21, 2020

    @fungiboletus

    This issue appear on search engines when you look for that.

    How can you convert a .js with JSDoc comments to a .ts file ? I cannot find how in the documentation. It's recommended to rename the file and fix it manually.

  14. karlhorky commented on Jan 6, 2021

    @karlhorky
    Contributor

    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. @typedef -> type alias, @template -> generics, etc).

    I assume such a converter / codemod exists somewhere, but I haven't been able to find it yet...

  15. danielo515 commented on Aug 7, 2021

    @danielo515

    If anyone ever finds such codemod, or builds it, please come back here and let us know

  16. whocaresk commented on Aug 11, 2021

    @whocaresk

    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
    this is probably what you're looking for

  17. karlhorky commented on Aug 11, 2021

    @karlhorky
    Contributor

    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)

  18. sandersn commented on Aug 12, 2021

    @sandersn
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Community ToolingThis 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.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions