Skip to content

Support 'Promote JSDoc comment to type annotation' #2916

@danquirk

Description

@danquirk

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:

  • Teach the parser how to parse full JSDoc format.
  • Emit JSDoc in .js files
  • Display a warning when users use a JSDoc type annotation instead of a TypeScript type annotation.
  • Support a tool/mode to generate a .d.ts from a .js file
  • In the language service, JS doc could be used to infer types for .js files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions