Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Clarify the pros and cons and the use cases for named export vs default export. #638

@shaunluttin

Description

@shaunluttin

Challenge

Both myself and my team have experienced some confusion around choosing between named exports and default exports.

On the one hand, official documentation suggests favoring export default.

The TypeScript handbook's page on Modules states:

If you’re only exporting a single class or function, use export default.

One conclusion of the ES Discuss module import topic is that:

The syntax should still favor default import.

On the other hand, prominent projects in the community favor a named export.

The TypeScript Deep Dive book has a page entitled "Avoid export default".

Angular makes heavy use of *.ts files that have a single export class or a single export function, which is in contrast with one of the red flags in the TypeScript handbook's page on Modules.

Suggestion

Create a new page in the handbook that focuses on choosing between a named and a default export.

  1. enumerate the pros and cons of named exports and default exports,
  2. enumerate the use cases for named exports and for default exports, and
  3. explain the concepts behind the existence of each.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions