google / google/closure-compiler

ES6 module support for "type-only import" like `goog.requireType` or TS `import type`

Open
#3,041 12 comments 9 reactions 0 assignees View on GitHub
feat internal-issue-created Modules triage-done
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.