If we specify a default export:
export class Foo {}
export default Foo;
then we can omit curly braces during import (as noted in this answer):
import { Foo } from "foo"; // becomes:
import Foo from "foo";
That's fine, but is there any non-stylistic reason to prefer one over the other in particular cases? For example, is there some convention, or is one incompatible with certain tools, or does one have a different meaning?
(Based on this discussion and others, my understanding is that export default
might have arisen as a way of handling the export of a single, primary object (like $
), which is now handled by import * as foo from "foo"
. Also, it seems the default import syntax does not enforce consistent naming (import fooAlias from "foo"
), while the standard import import { fooAlias } from "foo"
would be a compilation error unless the alias was explicit (Foo as fooAlias
). Apart from that, I haven't been able to find much information on when I should use one over the other.)