-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issuefeature-requestA request for a new featureA request for a new feature
Milestone
Description
Suggestion
π Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
import, type, esm
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
π Motivating Example
For a ESM-only package esm-package
, if we import types from it in a CommonJS file:
import type {SomeType} from 'esm-package';
TypeScript warns in typescript 4.6.0-dev.20211225
:
Module 'esm-package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.ts(1471)
For type-only import this shouldn't matter since it doesn't emit JavaScript code, so we can allow
π» Use Cases
Types, in some cases, are not possible to lazy import asynchronously, such as a top level export:
import type {SomeType} from 'esm-package';
export const DEFAULT_CONFIG: SomeType = {
// ...
};
robpalme, juliandm, ExE-Boss and Xunnamius
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issuefeature-requestA request for a new featureA request for a new feature