google / google/closure-compiler
ES6 module support for "type-only import" like `goog.requireType` or TS `import type`
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
The type system currently has no way of referencing types in ES6 modules without importing them. We need some sort of weak reference / import type for ES6 modules.
Bike shedding ideas dump:
1. Allow paths in type names. Use `:` as a delimiter for `path:type`.
```
/** @param {./foo.js:Type.Nested} n */
function foo(n) {}
```
2. Some commented out import syntax that brings the names into the type scope.
```
// @import {Type} from './foo.js';
/** @param {Type.Nested} n */
function foo(n) {}
```
3. Since the option above might be difficult with the current way we handle JsDoc (needs to be attached to something) and because `Type` doesn't really exist (it isn't a variable), we could modify the above option to act more like how we handle typedefs, i.e. annotate a variable declaration.
```
/** @import {Type} from './foo.js'; */
let Type;
/** @param {Type.Nested} n */
function foo(n) {}
```
Contributor guide
Assessment
This issue has not been assessed yet.