Skip to content

Allow enums in local scopes #3217

Closed

Description

Currently the following is allowed:

enum Color { red, green, blue }

function fun(myColor) {
    if (myColor == Color.red) {
        console.log("awesome");
    } else {
        console.log("bummer");
    }
}

This compiles, but gives a warning:

function fun(myColor) {
    enum Color { red, green, blue } // Warning "Statement expected"

    if (myColor == Color.red) {
        console.log("awesome");
    } else {
        console.log("bummer");
    }
}

Especially when refactoring existing JavaScript code, there are cases where an enum would be useful, but wouldn't be used outside of a single function. In those cases, I think it makes sense to allow the enum to be defined inside of the function's scope.

Activity

  1. danquirk commented on May 19, 2015

    @danquirk
    Member

    Presumably this could be considered along with other kinds of types we would allow in a future 'local types' feature. Edited the title appropriately.

  2. changed the title [-]Don't warn on function scoped enums?[/-] [+]Allow enums in local scopes[/+] on May 19, 2015
  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions