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

[api-extractor] Unable to follow symbol for "const" (part 2) #5077

Open
rickosborne opened this issue Jan 12, 2025 · 2 comments
Open

[api-extractor] Unable to follow symbol for "const" (part 2) #5077

rickosborne opened this issue Jan 12, 2025 · 2 comments

Comments

@rickosborne
Copy link

rickosborne commented Jan 12, 2025

Summary

This produces the same error as #3875 but has a very different repro.

Exporting and documenting a value as const causes the Unable to follow symbol for "const" error.

Repro steps

Type defs:

/**
 * Mixin added to function call options to indicate whether it should
 * throw, or silently swallow the error.
 */
export interface ThrowOnError {
	throwOnError?: boolean;
}

/**
 * Value of {@link ThrowOnError} which will avoid throwing.
 */
export const NO_THROW = {
	throwOnError: false,
} as const satisfies ThrowOnError;

Note the last line. I have it as const and I don't have it typed as ThrowOnError so I don't throw away the false value, but I also have satisfies so I can ensure I don't mistype it.

Note that the error still occurs if you remove satisfies. I'm leaving it here for context.

Workarounds:

  • Remove as const
  • Add @internal to the tsdoc.

Expected result: No error

Actual result: Error: Unable to follow symbol for "const"

Details

Above.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.49.1
Operating system? macOS Sonoma 14.7 on M1 Air
API Extractor scenario? Extractor.invoke
Would you consider contributing a PR? Not familiar at all with the codebase
TypeScript compiler version? 5.7.3
Node.js version (node -v)? v20.17.0
@rickosborne
Copy link
Author

Slight edit: Adding @internal doesn't act as a workaround — it still errors. I must have been confused.

@rickosborne rickosborne changed the title [api-extractor] Unable to follow symbol for "const" satisfies [api-extractor] Unable to follow symbol for "const" (part 2) Jan 12, 2025
@rickosborne
Copy link
Author

For posterity, I've found another workaround: don't export the as const value directly. Instead, split it into two variables, one with as const and the other with export:

/**
 * Mixin added to function call options to indicate whether it should
 * throw, or silently swallow the error.
 */
export interface ThrowOnError {
	throwOnError?: boolean;
}

// This is distinct from NO_THROW below due to a bug in api-extractor:
// https://github.com/microsoft/rushstack/issues/5077
const DO_NOT_THROW = Object.freeze({
	throwOnError: false,
} as const satisfies ThrowOnError);

/**
 * Value of {@link ThrowOnError} which will avoid throwing.
 */
export const NO_THROW = DO_NOT_THROW;

At a doc level, this still produces the correct ApiVariable.excerpt:

NO_THROW: Readonly<{
    readonly throwOnError: false;
}>

@iclanton iclanton moved this from Needs triage to AE/AD in Bug Triage Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

No branches or pull requests

1 participant