Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literal enums #10604

Closed
PanayotCankov opened this issue Aug 30, 2016 · 3 comments
Closed

Literal enums #10604

PanayotCankov opened this issue Aug 30, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@PanayotCankov
Copy link

PanayotCankov commented Aug 30, 2016

We are using string enums a lot. The following example is what gets pretty close:

/**
 * Allowed directions.
 */
export declare type FlexDirection = "row" | "column";
export namespace FlexDirection {
    /**
     * Align items in a row.
     */
    export const ROW: "row" = "row";

    /**
     * Align items in a column.
     */
    export const COLUMN: "column" = "column";
}

declare function go(direction: FlexDirection); // Hover "FlexDirection to see docs.
go(FlexDirection.ROW); // Hover "ROW" to see docs.
go("row");

Is there a better way to add documentation to a string literal type? Sometimes the meaning of the values is not all that visible, or requires examples. The only thing I miss in a literal type such as "row" | "column" at the moment is I can not easily associate docs with the 2 values.

Does it sound feasible to add a shorthand syntax for this similar to:

/**
 * Allowed directions.
 */
export literal /* whatever the keywords */ enum FlexDirection {
    /**
     * Align items in a row.
     */
    ROW = "row",

    /**
     * Align items in a column.
     */
    COLUMN = "column"
}
@mhegazy
Copy link
Contributor

mhegazy commented Aug 30, 2016

Duplicate of #3192

@mhegazy mhegazy closed this as completed Aug 30, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 30, 2016
@kitsonk
Copy link
Contributor

kitsonk commented Aug 30, 2016

You mean #7642 right (of which #9407 resolved it)? #3192 was string literals.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 30, 2016

my bad, it should be #1206.

#7642 does handle some of the cases, but there still a need for a string/symbol enum.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants