Skip to content

Feature request: allow using JSDoc types inside .ts files. #33189

Description

@trusktr

I am aware of #20774

Search Terms

allow using JSDoc inside TypeScript .ts files.

Suggestion

It would be AWESOME to allow types to be specified in comments inside of .ts files, just like with regular .js files.

Use Cases

I can not (do not want to) work within limitations of, current documentation solutions for TypeScript (f.e. TypeDoc, TSDoc, etc).

I'd rather use a more generic tool that understands JSDoc syntax, without regard for the source code (code agnostic), to make my documentation in a more flexible and customizable way (f.e. JSDOc with commentsOnly plugin which ignores source code, and considers only comments to be the source of truth for documentation.)

However, it'd still be nice not to duplicate types in the comments and in the source, where possible. So if I could write types in the comments (and still optionally have some types in the source as needed, especially for things that don't work in the comments), then that'd be awesome.

Examples

As shown in #20774, it unfortunately does not work.

Also I don't want to switch back to .js and lose certain type features that aren't covered by the commenting features.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Activity

  1. trusktr commented on Sep 2, 2019

    @trusktr
    ContributorAuthor

    For now, I'll duplicate all my types, because the flexibility and customizability that I get from handling JSDoc output in my own way is valuable. I don't like the mechanical output from TypeDoc for example, as it covers more than I need and is too complicated.

  2. trusktr commented on Sep 2, 2019

    @trusktr
    ContributorAuthor

    shynome (@shynome) By the way! Continuing from #20774, you can use JSDoc with TypeScript files, using the commentsOnly plugin, which will ignore all the source code, and read only the comments. :)

  3. sandersn commented on Sep 3, 2019

    @sandersn
    Member

    Our stance on types from jsdoc hasn't changed since #20774. jsdoc support for Typescript sounds like a better idea to me. In that case you would not use a commentsOnly plugin, but a plugin that understands Typescript.

    I'm not sure if the jsdoc maintainers are interested in supporting TS, but it is a large, and growing, chunk of JS code at this point.

    For now, I'm marking this as a duplicate of #20774

  4. typescript-bot commented on Sep 6, 2019

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  5. trusktr commented on Sep 6, 2019

    @trusktr
    ContributorAuthor

    Nathan Shively-Sanders (@sandersn) If instead of writing

    let s: string = 'asdf'

    we could also write

    /** @type {string} */
    let s = 'asdf'

    inside of a .ts file (which seems easy because the .js file support is already there), that'd be great. As far as doc generators, it would mean we wouldn't be strictly limited to those that understand TypeScript syntax.

    Seems like this is an easy change to make considering the machinery is already implemented. Would the TypeScript team be willing to take a PR that enables this for .ts files?

  6. typescript-bot commented on Sep 9, 2019

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  7. typescript-bot commented on Sep 12, 2019

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  8. trusktr commented on Jun 6, 2020

    @trusktr
    ContributorAuthor

    Can this be re-opened and kept open as a feature request?

  9. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions