Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ES export * as ns from form #4813

Closed
mhegazy opened this issue Sep 15, 2015 · 33 comments
Closed

Support ES export * as ns from form #4813

mhegazy opened this issue Sep 15, 2015 · 33 comments
Assignees
Labels
Committed The team has roadmapped this issue ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Sep 15, 2015

The ES7 proposal is available at: https://github.com/leebyron/ecmascript-more-export-from

The additions include:

reexporting default:

// proposed:
export v from "mod";

// symmetric to:
import v from "mod";
export {v};

reexporting as sub-module:

// proposed:
export * as ns from "mod";

// symmetric to:
import * as ns from "mod";
export {ns};

also allowing combining

// proposed
export v, {x, y as w} from "mod"
// symmetric to
import v, {x, y as w} from "mod"
As well as

// proposed
export v, * as ns from "mod"
// symmetric to
import v, * as ns from "mod"
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus ES7 Relates to the ES7 Spec labels Sep 15, 2015
@vladima vladima changed the title Support porposed ES7 export form forms Support proposed ES7 export form forms Sep 15, 2015
@vladima vladima changed the title Support proposed ES7 export form forms Support proposed ES7 export from forms Sep 15, 2015
@vilicvane
Copy link
Contributor

👍

@mhegazy mhegazy changed the title Support proposed ES7 export from forms Support proposed ES.Next export from forms Feb 4, 2016
@mhegazy mhegazy added ES Next New featurers for ECMAScript (a.k.a. ESNext) and removed ES7 Relates to the ES7 Spec labels Feb 4, 2016
@mhegazy mhegazy changed the title Support proposed ES.Next export from forms Support proposed ES export from forms Feb 4, 2016
@nevir
Copy link

nevir commented Jul 25, 2016

This would be incredibly helpful for supporting intellisense for JavaScript projects in VS Code; export * as foo from './foo'; seems pretty widely used

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Nov 21, 2016

At first I thought this (the ECMAScript proposal) was a bad idea because the preponderance of existing export forms is a source of confusion for newcomers. However, I've come around to the idea that the asymmetry between the import and export forms is actually a source of confusion in itself so adding this would be beneficial.

@jetpacmonkey
Copy link

Is there any chance of this being added sometime soon? I've been using this feature in my codebase with the stage-1 babel preset, and was hoping to start using typescript to get gradually get some static typechecking, but typescript throws a bunch of errors every time it comes across export x from './y';

@mikew
Copy link

mikew commented May 10, 2017

Our team's projects usually has a common file for developers to import common things from, without having to worry about where they come from:

import {
  React,
  PropTypes,
  PureComponent,
  Button,
  connect,
} from './common'

Without export from, this common file will double in size and have needless duplication and some lines that can be confusing to newcomers.

// This ...
export React, {
  PureComponent,
  PropTypes,
} from 'react'

// ... becomes ...
import * as _React from 'react'
export const React = _React
export const PropTypes = _React.PropTypes
export const PureComponent = _React.PureComponent

@mikew
Copy link

mikew commented May 10, 2017

Even more strange that export { connect } from 'react-redux' works.

@nevir
Copy link

nevir commented May 10, 2017 via email

@mikew
Copy link

mikew commented May 10, 2017

Almost, except then it's module "@types/react/index" has no exported member 'default'.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented May 11, 2017

@mikew That is true but the same issue would apply to the proposed

export React, {
  PureComponent,
  PropTypes,
} from 'react';

The default issue is a complex issue stemming from a convoluted set of incompatibilities and disparate assumptions made by standards, languages, environments, loaders, bundlers, runtimes, and transpilers.

However, it is entirely orthogonal to this proposal.

If you can write

import React from 'react';

and it works at runtime, set the --allowSyntheticDefaultImports flag.

@mjbvz
Copy link
Contributor

mjbvz commented Jun 29, 2017

#9906 tracked the proposed export default from ( https://github.com/tc39/proposal-export-default-from ) and was marked as a duplicate of this

Adding this comment to make sure the request for supporting export default from isn't potentially overlooked as part of this issue

@weswigham
Copy link
Member

export * as ns from "foo" was shipped in v8 7.2, meaning current node and chrome can technically support it in their modules implementations - the downlevel isn't hard (just rewrite into

import * as ns from "foo";
export { ns }

and feed down the transformer pipeline). This does imply a new module target that doesn't downlevel it, though, which means a bump of the exnext module and the addition of es2019 modules - the exact timing is a little muddy, since AFAIK it's shipped in v8 even though the proposal is still stage 1.

cc @RyanCavanaugh so we're aware

@Jessidhia
Copy link

Jessidhia commented Oct 3, 2019

export * as ns from "foo" was merged and is now officially part of the language tc39/ecma262#1174

It probably should be preserved instead of downleveled in esnext / es2020 emits.


Tangentially, this syntax is useful because of a bug in webpack 4 (fixed in webpack 5). It treats export * as ns from ... differently from the downlevel form, and is no longer capable of "tree shaking" if it's written in the downlevel form.

@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Oct 14, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.0 milestone Oct 14, 2019
@DanielRosenwasser DanielRosenwasser changed the title Support proposed ES export from forms Support proposed ES export * as ns from form Oct 28, 2019
@DanielRosenwasser
Copy link
Member

Changed the title since there is currently no export default version of this.

@Jessidhia
Copy link

It's still mis-titled because it's no longer "proposed"; it is already in the spec 😉

@ExE-Boss
Copy link
Contributor

ExE-Boss commented Nov 8, 2019

I’ve now opened #35010 for the export default from form.

@DanielRosenwasser
Copy link
Member

Thanks @Kingwl!

@katis
Copy link

katis commented Jan 22, 2020

Previously I liked using TS namespaces and declaration merging for creating FP-style modules, without needing the MyModule.T convention:

export type Foobar = { }

export namespace Foobar {
  export function doStuff(foobar: Foobar) { }
}
import { Foobar } from './Foobar'

Foobar.doStuff(fb)

Namespaces are not really the way to go any more, babel doesn't support them, they probably aren't tree-shakeable etc. But I was hoping that the export * as ns syntax could be used as a replacement, like this:

export type Foobar = import('./Foobar').Foobar

// Or:
// export type { Foobar } from './Foobar'

export * as Foobar from './Foobar'

This seems to pass the nightly compiler, but the compiler only knows that Foobar is re-exported as a type, not a value. It would be great if the compiler could merge them into a combined value & type like with namespaces.

@rbuckton
Copy link
Member

@katis: I filed #36792 with the content of your comment above.

I'm closing this issue as it was fixed in #34903.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests