Skip to content

Support deferred re-exportsΒ #64602

Description

πŸ” Search Terms

export defer, deferred re-exports, deferred re-exports, lazy barrel files

βœ… Viability Checklist

⭐ Suggestion

Support the TC39 Deferred Re-exports proposal, which is now at Stage 2.7, including named and namespace re-exports:

export defer { a } from "./a.js";
export defer * as b from "./b.js";

Preserve the syntax in supported JavaScript output and declaration files, while retaining the types of exported bindings.

πŸ“ƒ Motivating Example

// a.ts
export function a(c: number, d: number): number {
    return c + d;
}

// b.ts
export function b(c: number, d: number): number {
    return c - d;
}

// c.ts
export defer { a } from "./a.js";
export defer { b } from "./b.js";

// d.ts
import { a } from "./c.js";

const b: number = a(1, 2);

Importing a does not require loading the unused module b.ts.

πŸ’» Use Cases

  1. What do you want to use this for?
    Provide a shared entry point without loading unused modules
  2. What shortcomings exist with current approaches?
    Ordinary static re-exports load unused dependencies in native ESM.
  3. What workarounds are you using in the meantime?
    Alternatives are direct module imports or dynamic import().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions