typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Fix typedef binding with CJS `exports=`

Open sandersn opened this issue 8 months ago • 0 comments

With this PR, top-level typedefs in file with commonjs exports (module.exports=x or exports=x) are no longer added as exports of the file. They're added as exports of whatever is export=. I'm not sure that I declared the local and export='d symbols in the right way, so I'd appreciate expert opinions there.

The big change compared to Strada is that only top-level typedefs are exported. But it never made sense for these two scoped type aliases to be exported, let alone both:

function one() {
  /** @typedef {string} T */
  /** @type {T} */
  var s = 's'
}
function two() {
  /** @typedef {number} T */
  /** @type {T} */
  var n = 1
}
/* @type {T} */
var error = "I AM ERROR"

It's especially weird that a scoped alias would be inaccessible at the top-level, but then accessible in a different file.

sandersn avatar Apr 25 '25 21:04 sandersn