Skip to content

Feature suggestion: Compile-time reflection of string literal unions and enums #9182

Closed

Description

@XorgonTheTypesafe

say we have

type Fish = "one" | "two" | "red" | "blue";

or

enum Fish
{
   one,
   two,
   red,
   blue
}

It would be useful to have a way to refer to the possible values at runtime:
something like __valuesof(Fish) would transpile to
["one" , "two" , "red", "blue"] in both cases.

Also consider __enummap(Fish) that would transpile to

{
    "one":1,
    "two":2,
    "red":3,
    "blue":4    
}

or explicit enum values if specified. This would allow C#'s Enum.Parse functionality

Activity

  1. mhegazy commented on Jun 15, 2016

    @mhegazy
    Contributor

    The issue of type serialization/"reflection" has been discussed multiple times (#2902, #2577, #3060). we already have #3628 to track this discussion; so i suggest moving this proposal to that issue.

  2. 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

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