I can define a function and then export as default, define it an export it inline, or define it and export it as default inline:
function myFunc() {
...
}
export default myFunc;
export function myFunc2() {
...
}
export default function myFunc3(param) {
...
}
I can define a class and then export as default, define it and export it inline, or define it and export it as default inline:
class MyClass {
...
}
export default MyClass;
export class MyClass2 {
...
}
export default class MyClass3 {
...
}
Cool, so classes and functions are consistent. Now, constants:
Define and then export as default:
const myConst = 42;
export default myConst;
Define and export inline:
export const myConst = 42;
Those are fine. But I cannot define it and export as default inline:
export default const myConst = 42; // nope -- syntax error!
My question: why are constants different than classes and functions in this regard? They're all exportable, all exportable as defaults. Why can't I do it inline with a constant?
I found Why Is `Export Default Const` invalid? while googling. I believe the asker was trying to ask the same question I am, but there is a highly upvoted, accepted answer which does not answer my question. I am not asking for the technical reason the compiler rejects the syntax. I am looking to understand why the language is designed this way.
If it helps, the answer might take the form of "if this syntax were supported, [thing] would happen," or "it used to work that way, but we removed it because [thing] happened," or "there's an open discussion on adding this to the spec, see [here]."
If the distinction between TypeScript and JavaScript is in any way relevant to the answer, please clarify.