Goal:
Allow grouping multiple exports under a common namespace at export time, without needing wrapper objects or intermediate files.
Idea 1: Object-like export grouping
const foo = () => {}
const bar = 33
export { foo, bar } as 'qux'
Similar to :
-
export const qux = { foo, bar }
-
import * as qux from 'qux'
Considerations:
-
Such a proposal would elevate
as
into a clear boundary marker between local clarity and global coherence, letting authors keep intuitive local names while exporting under meaningful, conflict-free namespaces. -
Using
import * as qux from 'qux'
is a consumer’s choice whereasexport { foo, bar } as qux
(if it existed) would be a maintainer’s decision, a deliberate part of the module’s public API design, shaping how the module is meant to be consumed. -
Grouping export statements at the end of a file improves readability by centralizing the module’s public API, so you don’t have to scroll and hunt for scattered export keywords.
Primarily designed for libraries, a real-world use case could be:
// bezier.js
function quadratic() { ... }
function cubic() { ... }
function quartic() { ... }
export { quadratic, cubic, quartic } as 'bezier'
Other syntax options:
Idea 2: Inline Namespace Export
const foo = () => {}
const bar = 42
export namespace qux {
export { foo, bar }
}
Idea 3: Object-like export grouping
export group qux {
export const foo = ...
export function bar() { ... }
}
For all these, the consuming module could write:
import { qux } from 'mymodule'
qux.foo()
Final thought:
My personal inclination leans toward idea 1; I do still wonder about readability in nested as cases like:
export {
foo,
bar as baz,
} as 'qux'
—but honestly, even that feels readable to me.