question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for opting out of jsdoc @typedef exports

See original GitHub issue

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
    
    }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:16
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
andrewbranchcommented, Sep 23, 2021

Agreed this is not ideal. Not sure how best to indicate that it shouldn’t be exported. Maybe another JSDoc tag on the comment:

/**
 * @typedef {import("./FileA.js").Num} Num
 * @local
 */

@local isn’t something listed on https://jsdoc.app. @private or something? We kind of try not to just make up JSDoc things willy nilly, but this feels like a problem we made so the solution will probably have to be made by us too. /cc @sandersn?

0reactions
jespertheendcommented, Nov 21, 2021

I suppose this might be a duplicate of #22160 At least that would solve the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to extend a typedef parameter in JSDOC? - Stack Overflow
I found this solution and this works very fine for me. originally from here /** * @typedef {Object} ChildType * @property {String} childProp ......
Read more >
Use JSDoc: @exports
Overview. Use the @exports tag when documenting JavaScript modules that export anything other than the "exports" object or the "module.exports" property.
Read more >
JSDoc refer to type in another module
Hello. It seems like refering to a type from another module does not work using js doc. For instance: Module 1 /** @module...
Read more >
eslint-plugin-jsdoc - npm
settings.jsdoc.ignorePrivate - Disables all rules for the comment block on which a @private tag (or @access private ) occurs. Defaults to false ...
Read more >
Jsdoc export typedef - Caritas Castellaneta
If you encountered the "Support for opting out of jsdoc @typedef exports", while you are working on microsoft/TypeScript please share your code example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found