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 export default const #18737

Closed
k8w opened this issue Sep 25, 2017 · 6 comments
Closed

Support export default const #18737

k8w opened this issue Sep 25, 2017 · 6 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@k8w
Copy link

k8w commented Sep 25, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
2.6.0-dev.20170921

Code

export default const a = 'a';

Expected behavior:
Compile succ

Actual behavior:
Compile error

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Sep 25, 2017

This is actually not currently supported by the ECMAScript specification.

Currently, export default may only be combined with the various declaration forms for class and function.

There was a fair amount of discussion about this a while ago on https://esdiscuss.org. I'll try to find the thread and link it.

@aluanhaddad
Copy link
Contributor

Hear is the thread, it dates to 2013 and covered the topic in depth. https://esdiscuss.org/topic/why-is-export-default-var-a-1-invalid-syntax

@mhegazy mhegazy added Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript labels Sep 25, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 25, 2017

We recommend taking these features to TC39 instead.

@mhegazy mhegazy closed this as completed Sep 25, 2017
@TedDriggs
Copy link

What about enums? export default enum is fine, but export default const enum doesn't work.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 20, 2017

@TedDriggs , Please see #3792 (comment)

@gruppjo
Copy link

gruppjo commented Apr 19, 2018

For others having the same problem:

You can just do it like that:

export const a = 5;
export default a;

The issue is that the syntax could be ambiguous, that's why anything link export default const a = 5; won't work. Example:

// nonsense
export default const a = 5, b = 5, c = 5;

Read more here, as @aluanhaddad already pointed out: https://esdiscuss.org/topic/why-is-export-default-var-a-1-invalid-syntax

@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants