google / google/closure-compiler
Using Types from Modules in Non-global Scopes
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Currently, the following type references work well due to the InlineAlias pass:
``` js
const Foo = require('./foo');
/** @param {Foo} */
function bar(foo) {}
```
However, as soon as the code is no longer in a global scope (like an IIFE), then the pass doesn't function and the type cannot be resolved.
``` js
(function() {
const Foo = require('./foo');
/** @param {Foo} */
function bar(foo) {}
})()
```
This easily occurs with the changes in #1630.
The current work around is to use module path references:
``` js
(function() {
const Foo = require('./foo');
/** @param {./foo} */
function bar(foo) {}
})()
```
I think it's overly restrictive for this to only function in the global scope. It makes the functionality very brittle and hard to explain to users.
Contributor guide
Assessment
This issue has not been assessed yet.