Aron
Aron

Reputation: 9248

Why is `export * as Name from './module'` not a thing in TypeScript?

Many of the import forms in JavaScript and TypeScript have export parallels, to allow for easy re-exporting of values and types. E.g.

export { A, B } from './module'

or

export { default as Name } from './module'

Ohers don't, for reasons that make sense to me. E.g.

export Name from './module'

wouldn't make sense, as we're not specifying which name we want to re-export Name under.

But why does this not work:

export * as Name from './module'

Isn't it clear that we're exporting all named exports from './module' under the Name name? To me it seems obvious that our intention here is to group all the exports from the file into an object which we then export just like another named export, similarly to how this is ok

import * as Name from './module'

because it's clear that we're importing all exports under the Name name

Upvotes: 1

Views: 285

Answers (1)

R Xy
R Xy

Reputation: 307

It can't be used because it hasn't appeared in the ES Module specification. It is currently, together with the export name from 'mod' syntax, a stage 1 proposal.

See:

You can use these features now by using Babel, a JavaScript transpiler.

Upvotes: 1

Related Questions