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
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.
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
We recommend taking these features to TC39 instead.
What about enums? export default enum is fine, but export default const enum doesn't work.
@TedDriggs , Please see https://github.com/Microsoft/TypeScript/issues/3792#issuecomment-303526468
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
Most helpful comment
We recommend taking these features to TC39 instead.