Skip to content

Declaration merging #28

@aspirisen

Description

@aspirisen

Hello, will it be possible to merge declarations, like that:

module Hello {
    export const A = 3;
}

module Hello {
    export const B = 4;
}

console.log(Hello.A, Hello.B) // 3, 4

This is how namespaces works in typescript (previously they called modules). Playground

One huge benefit of namespaces is that they can be merge with functions declarations. Playground

function Hello() {
    return 3
}

namespace Hello {
    export const meta = 4
}

console.log(Hello(), Hello.meta) // 3, 4

This is a widely used pattern i.e. in react. Playground

export function Component(props: PropsWithChildren) {
    return <div>{props.children}</div>
}

export namespace Component {
    export function Icon() {
        return <i className="icon" />
    }
}

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