Skip to content

Automatic barrel by folder, unless an index.ts is explicitly provided #31284

@alshdavid

Description

@alshdavid

Using an index.ts in the root directory of each folder to export it's contents is a great way to organise your projects.

However explicitly providing a barrel in each folder then exporting each file in that barel is both cumbersome, cluttering and prone to mistakes.

What I'd like to see is each folder has all of it's exports available to import, unless that folder has an index.ts and explicitly re-exports.

/my-module
    index.ts
    part-1.ts
    part-2.ts
    part-3.tsx

The above folder structure would be replaced with

/my-module
    part-1.ts
    part-2.ts
    part-3.tsx

and the import statement could still be

import {} from './my-module'

For an implementation example/reference, check out Go (Golang). Achieving a similar behaviour to it would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions