Skip to content

Support for opting out of jsdoc @typedef exportsΒ #46011

@jespertheend

Description

@jespertheend

Suggestion

πŸ” Search Terms

jsdoc typedef export #43207 #23692

βœ… Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Currently when using /** @typedef {Number} Num */ the type Num is automatically exported when the comment is in the root scope. I'd like to prevent this from happening.

πŸ“ƒ Motivating Example πŸ’» Use Cases

My problem:
FileA.js declares /** @typedef {Number} Num */
FileB.js uses this type a bunch of times, so instead of using /** @type {import("./FileA.js").Num} */ everywhere, it declares it once at the top of the file: /** @typedef {import("./FileA.js").Num} Num */ and then uses Num everywhere in the file.

The problem is that doing it this way in all files creates a lot of exports of the same type and it's not always clear which one is the original export. This creates a rather big list with Intellisense:
image

A woraround is to wrap the type in parentheses, this causes the typedef to be limited to that scope, but this is not always feasible. I.e:

{
    /** @typedef {import("./FileA.js").Num} Num */
    /**
     * @param {Num}
     */
    export default function foo(x) { // <-- error, export needs to be top level
    
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusNeeds 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