Skip to content

const enum & namespace merged error #28793

@mengjian-github

Description

@mengjian-github

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms:

Code

const enum Weekday {
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}
namespace Weekday {
    export function isBusinessDay(day: Weekday) {
        switch (day) {
            case Weekday.Saturday:
            case Weekday.Sunday:
                return false;
            default:
                return true;
        }
    }
}

export default Weekday;

Expected behavior:
no errors.

Actual behavior:
got an error "Enum declarations can only merge with namespace or other enum declarations."

Playground Link:
https://www.typescriptlang.org/play/index.html#src=const%20enum%20Weekday%20%7B%0D%0A%20%20%20%20Monday%2C%0D%0A%20%20%20%20Tuesday%2C%0D%0A%20%20%20%20Wednesday%2C%0D%0A%20%20%20%20Thursday%2C%0D%0A%20%20%20%20Friday%2C%0D%0A%20%20%20%20Saturday%2C%0D%0A%20%20%20%20Sunday%0D%0A%7D%0D%0Anamespace%20Weekday%20%7B%0D%0A%20%20%20%20export%20function%20isBusinessDay(day%3A%20Weekday)%20%7B%0D%0A%20%20%20%20%20%20%20%20switch%20(day)%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20Weekday.Saturday%3A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20Weekday.Sunday%3A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20false%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20default%3A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aexport%20default%20Weekday%3B%0D%0A

Related Issues:
#16804

I just found the realated issues, but no solution for me. I can't understand why this is not a bug. The playground shows what I expected in compilation.
I hope not to report an error, while the compilation result is exactly what I want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions