question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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) {}
  1. 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) {}
  1. 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:open
  • Created 5 years ago
  • Reactions:9
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ChadKillingsworthcommented, Aug 15, 2018

This isn’t restricted to ES6 modules. CommonJS need the same thing.

2reactions
evmarcommented, Aug 14, 2018

#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.

var x: import('./y).Type; 

https://davidea.st/articles/typescript-2-9-import-types

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found