google / google/closure-compiler
@typedef is not visible outside of CommonJS module
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Types that are defined inside a CommonJS module with `@typedef` are not visible outside of that module. This short example demonstrates the issue.
# a.js
``` js
/**@typedef{{
one: string,
two: number
}}*/
var MyObject;
/**@const*/
exports.MyObject = MyObject;
```
# b.js
``` js
var a = require("./a");
/**@type{!a.MyObject}*/
var b = { one: "hello", two: 3};
```
# output
``` bash
$ java -jar compiler.jar --process_common_js_modules --entry_point b --js_output_file out.js \
--jscomp_error checkTypes a.js b.js
b.js:3: ERROR - Bad type annotation. Unknown type a.MyObject
/**@type{!a.MyObject}*/
^
1 error(s), 0 warning(s)
```
A workaround is to copy the `@typedef` to all the modules that use it.
Contributor guide
Assessment
This issue has not been assessed yet.