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 for enum-like object declarations enums #1740

Closed
michkot opened this issue Oct 15, 2021 · 2 comments
Closed

Support for enum-like object declarations enums #1740

michkot opened this issue Oct 15, 2021 · 2 comments
Labels
enhancement Improved functionality

Comments

@michkot
Copy link

michkot commented Oct 15, 2021

Search Terms

as const enum
enum-like objects
union of literals

Problem

The support for #1675 works only for .ts files, but not for .d.ts files (not even those generated from the supported syntax). Could the suport for "as const" object enums be extended for enum-object declarations?
See the #1675 for full context.

eg. in addition to

/** @enum /
export const EntryPointStrategy = {
/
*
* abcd
*/
Resolve: "resolve",
} as const;

there would be also support to detect the following as an enum too:

/** @enum /
export ( declare ) const EntryPointStrategy: {
/
*
* abcd
*/
readonly Resolve: "resolve",
};

(This is especially needed when typedoc is executed after pre-processing the .ts APIs by e.g. tsc / api-extractor to .d.ts)

There is even a "convenience variant" for cases when this is manually written:

/** @enum /
export const EntryPointStrategy: Readonly<{
/
*
* abcd
*/
Resolve: "resolve",
}>;

but that might be more annoying to detect.

@michkot michkot added the enhancement Improved functionality label Oct 15, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 17, 2021

Turns out I could do one better. So long as the property types are string literals, TypeDoc will recognize @enum on variables now :) Don't even need readonly since the type being a string literal makes the property effectively readonly

@michkot
Copy link
Author

michkot commented Dec 21, 2021

I have played around with this a bit recently again, and it seems we are missing per-element jsdoc in all but the standard enum case (at latest version). I am gonna open a follow-up issue once I have time to summarize it.

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

No branches or pull requests

2 participants