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

@enum incorrectly handles type declared before value #2719

Closed
Gerrit0 opened this issue Sep 29, 2024 · 3 comments
Closed

@enum incorrectly handles type declared before value #2719

Gerrit0 opened this issue Sep 29, 2024 · 3 comments
Milestone

Comments

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Sep 29, 2024

My warnings look slightly different:

[warning] Failed to resolve link to "searchValue" in comment for __type.replaceValue
[warning] Failed to resolve link to "replaceValue" in comment for __type
[warning] Failed to resolve link to "searchValue" in comment for __type

Nowhere in my codebase is anything named searchValue or replaceValue.

Repro is on this branch: https://github.com/electrovir/date-vir/tree/broken-docs. Repro steps are as follows:

  1. npm i in root
  2. cd packages/date-vir && npm run docs

I'm also getting a project warning which I don't understand because I've never gotten it before and I use the same config in all my repos.

[warning] date-vir (Project), defined in ./src/index.ts, does not have any documentation

I've narrowed the issue down to this line: https://github.com/electrovir/date-vir/blob/broken-docs/packages/date-vir/src/timezone/timezones.ts#L10 (notice Timezone is both a type and a const).

When I remove line 10, TypeDoc doesn't error out. It appears that TypeDoc is unable to handle this situation where an object is made to behave like a TypeScript enum.

I haven't found a workaround yet; adding @ignore doesn't work.

Originally posted by @electrovir in #2715 (comment)

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Sep 29, 2024

The @enum issue can be reduced to:

export const allTimezoneNames = ["Africa/Abidjan", "Africa/Accra"] as const;

export type ArrayElement<ArrayType extends ReadonlyArray<any>> =
    ArrayType[number];

export type Timezone = ArrayElement<typeof allTimezoneNames>;

/**
 * @enum
 */
export const Timezone = allTimezoneNames.reduce(
    (acc, timezoneName) => {
        acc[timezoneName] = timezoneName;
        return acc;
    },
    {} as Record<string, string>,
) as Readonly<{
    [SpecificTimezoneName in Timezone]: SpecificTimezoneName;
}>;

Gerrit0 added a commit that referenced this issue Sep 29, 2024
@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Sep 29, 2024

[warning] date-vir (Project), defined in ./src/index.ts, does not have any documentation

This is caused by a second bug in the @enum handling code, where types are converted with the wrong context argument.

@Gerrit0 Gerrit0 modified the milestones: v0.26.7, v0.27.0 Sep 29, 2024
@Gerrit0 Gerrit0 closed this as completed Sep 29, 2024
@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Sep 29, 2024

Temporary workaround, swap the declaration order of type Timezone and const Timezone so that the variable declaration comes first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant