Skip to content

Support for as const enums #1675

@Gerrit0

Description

@Gerrit0

Search Terms

as const, enumerations

Problem

Since TypeScript's enum is rather inconvenient to work with, some packages define their own enum-like objects, TypeDoc does this too.

/**
* Defines how entry points are interpreted.
* @enum
*/
export const EntryPointStrategy = {
/**
* The default behavior in v0.22+, expects all provided entry points as being part of a single program.
* Any directories included in the entry point list will result in `dir/index.[tj]sx?` being used.
*/
Resolve: "resolve",
/**
* The default behavior in v0.21 and earlier. Behaves like the resolve behavior, but will recursively
* expand directories into an entry point for each file within the directory.
*/
Expand: "expand",
/**
* Alternative resolution mode useful for monorepos. With this mode, TypeDoc will look for a package.json
* and tsconfig.json under each provided entry point. The `main` field of each package will be documented.
*/
Packages: "packages",
} as const;

However, the generated documentation doesn't make it obvious that this value should be treated as an enumeration.

image
image

Suggested Solution

Detect variables annotated with @enum with all readonly properties that are string literals, and convert them as an enumeration.

If there is also a type alias by the same name whose content is typeof T[keyof typeof T], remove it from the documentation since enums are also types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions