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

Support enum-like objects with numeric literal values #1918

Closed
ejuda opened this issue Apr 11, 2022 · 2 comments · Fixed by #1920
Closed

Support enum-like objects with numeric literal values #1918

ejuda opened this issue Apr 11, 2022 · 2 comments · Fixed by #1920
Labels
enhancement Improved functionality

Comments

@ejuda
Copy link
Contributor

ejuda commented Apr 11, 2022

Search terms

enum, enum-like object

Problem

TypeDoc already supports enum-like objects with string literal values via #1675 and #1740. However, enum-like objects with numeric literal values are not supported. For the following code example:

// index.d.ts

/**
 * This enumeration defines some values.
 *
 * @enum
 */
export declare const SomeStringLiteralEnum: {
    /**
     * This is the auto property.
     */
    readonly AUTO: "auto";
    /**
     * This is the manual property.
     */
    readonly MANUAL: "manual";
};

/**
 * This enumeration also defines some values.
 *
 * @enum
 */
 export declare const SomeNumericLiteralEnum: {
    /**
     * This is the auto property.
     */
    readonly AUTO: 0;
    /**
     * This is the manual property.
     */
    readonly MANUAL: 1;
};

TypeDoc will document SomeStringLiteralEnum as an enum and SomeNumericLiteralEnum as a variable:

image

Suggested Solution

Support enum-like objects with numeric literal values in the same way as those with string literal values. I think it would only require some minor changes in src/lib/converter/symbols.ts.

@ejuda ejuda added the enhancement Improved functionality label Apr 11, 2022
@ejuda
Copy link
Contributor Author

ejuda commented Apr 11, 2022

If this is something we'd like to support in TypeDoc, I'd be happy to contribute this feature - I've already done some tinkering in the source code. :)

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 11, 2022

Seems reasonable to me, PR welcome! :)

ejuda added a commit to ejuda/typedoc that referenced this issue Apr 12, 2022
TypeDoc already supports enum-like objects with string literal values
via TypeStrong#1675 and TypeStrong#1740. Enum-like objects with numeric literal values
should also be supported, as they are a popular choice for developers
wishing to avoid use of TypeScript enums.

This PR adds support for such objects. Tests and a new example have
been added to cover this type of object.

Resolves TypeStrong#1918.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants