-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
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:
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
}
}