ES6 module support for "type-only import" like `goog.requireType` or TS `import type`
See original GitHub issueThe 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:
- Allow paths in type names. Use
:
as a delimiter forpath:type
.
/** @param {./foo.js:Type.Nested} n */
function foo(n) {}
- 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) {}
- 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) {}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there's no remnant of...
Read more >type-only imports — A new TypeScript feature that benefits ...
Example 1 — Ambiguous re-export · Babel removes everything from our types module because it only contained types, which have no use in...
Read more >Content Types - esbuild
For historical reasons, the TypeScript compiler compiles ESM (ECMAScript module) syntax to CommonJS syntax by default. For example, import * as foo from...
Read more >Content Types - ESBuild
For historical reasons, the TypeScript compiler compiles ESM (ECMAScript module) syntax to CommonJS syntax by default. For example, import * as foo from...
Read more >Do I need to use the "import type" feature of TypeScript 3.8 if ...
As far as I understand it is meant to fix specific problems which seems mostly to happen when importing from .js files. I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This isn’t restricted to ES6 modules. CommonJS need the same thing.
#1 resembles the analogous TS feature, I think. I’ve never used it myself but I think it was meant to look like dynamic imports, under the reasoning that imports in type position don’t have runtime implications.
https://davidea.st/articles/typescript-2-9-import-types