GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow enums in local scopes · Issue #3217 · microsoft/TypeScript

Allow enums in local scopes #3217

New issue
Copy link
New issue
Copy link
Closed
#3266
Closed
Allow enums in local scopes#3217
#3266
Copy link
Assignees
ahejlsberg
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
TypeScript 1.6

Description

@joshuacc
Joshua Clanton (joshuacc)
opened on May 19, 2015
Issue body actions

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
    Dan Quirk (danquirk)
    on May 19, 2015
    Member
    More actions

    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. Dan Quirk (danquirk)
    changed the title [-]Don't warn on function scoped enums?[/-] [+]Allow enums in local scopes[/+] on May 19, 2015
  3. Dan Quirk (danquirk)
    added
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    on May 19, 2015
  4. Mohamed Hegazy (mhegazy)
    assigned
    Anders Hejlsberg (ahejlsberg)
    on May 21, 2015
  5. Mohamed Hegazy (mhegazy)
    added this to the TypeScript 1.6 milestone on May 21, 2015
  6. Anders Hejlsberg (ahejlsberg)
    closed this as completedin #3266on May 31, 2015
  7. Anders Hejlsberg (ahejlsberg)
    added
    FixedA PR has been merged for this issueA PR has been merged for this issue
    on May 31, 2015
  8. Ryan Cavanaugh (RyanCavanaugh)
    added
    CommittedThe team has roadmapped this issueThe team has roadmapped this issue
    on Jun 1, 2015
  9. microsoft
    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

Assignees

  • @ahejlsberg
    Anders Hejlsberg (ahejlsberg)

Labels

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

Type

No type

Projects

No projects

    Milestone

    • TypeScript 1.6

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.