Navigation Menu

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

Third-Party symbol not resolved in @link #2030

Closed
danielwiehl opened this issue Aug 11, 2022 · 5 comments
Closed

Third-Party symbol not resolved in @link #2030

danielwiehl opened this issue Aug 11, 2022 · 5 comments
Labels
enhancement Improved functionality question Question about functionality

Comments

@danielwiehl
Copy link

danielwiehl commented Aug 11, 2022

Search terms

link; link to third-party symbol; third-party symbol; will break in v0.24

Question

We generate API documentation for a library that heavily depends on a third-party library. In many comments, we refer to types of that third-party library using the link tag, e.g., {@link Session}.

When generating the documentation, for every link to the third-party library, we get an error like Failed to resolve {@link Session} in ... with declaration references. This link will break in v0.24. That makes sense since TypeDoc has no idea where to find the respective documentation site. We learned that we could write a custom TypeDoc plugin similar to the MDN link plugin for providing a mapping for our third-party symbols. But, it turned out that this only works for symbols referenced in code but not for symbols referenced in links via the @link tag.

Below an example. The MessageClient class references the third-party symbol Session both by link and in the constructor.

import {Session} from 'solclientjs';

/**
 * See {@link Session} for more information.  // will not be resolved
  */
export class MessageClient {

  constructor(session: Session) { // will be resolved if writing a custom TypeDoc plugin that adds a resolver for the unknown symbol `Session`
  }
}

Did we miss something?

Also, having to write a custom TypeDoc plugin for solely providing associations of third-party symbols to their documentation site seems very cumbersome. Isn't there a way to configure the mappings directly in tsconfig.json under typedocOptions? That would be so straightforward, sort of like this. What do you think about it?

    "typedocOptions": {
      ... omitted
      "validation": {
        "invalidLink": true
      },
      "externalSymbolLinkMappings": { // something like this would be great to not have to write a custom TypeDoc plugin
        "solclientjs": {
          "Session": "https://docs.solace.com/API-Developer-Online-Ref-Documentation/js/solace.Session.html"
        }
      }
    }
@danielwiehl danielwiehl added the question Question about functionality label Aug 11, 2022
@danielwiehl danielwiehl changed the title Third-Party symbols not resolved in links Third-Party symbols not resolved in @link Aug 11, 2022
@danielwiehl danielwiehl changed the title Third-Party symbols not resolved in @link Third-Party symbol not resolved in @link Aug 11, 2022
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Aug 14, 2022

No, you didn't miss anything. Since Session isn't actually included in your documentation, TypeDoc can't resolve it to a real link.

@links are resolved with declaration references, and do not take into consideration what symbols you have in scope at the location the @link tag is declared. This is a difference to how VSCode resolves links, but means that links do not have the potential for changing depending on if you run on your .ts files or compiled .d.ts files. (And, the aim for 0.24 is generation from previously created json outputs, so we won't have that info then)

Letting plugins add resolvers for external {@link} tags seems like a good idea, doing that would make the following work:

/**
 * See {@link solclientjs!Session} for more information.
  */
export class MessageClient {}

I like the idea of externalSymbolLinkMappings for one off additions. The main reason I went for plugin based resolution is that they can be easily shared across projects, and there are ridiculous numbers of links for some libraries, (typedoc-plugin-mdn-links has ~500)

@Gerrit0 Gerrit0 added the enhancement Improved functionality label Aug 15, 2022
@danielwiehl
Copy link
Author

Thank you @Gerrit0 for the detailed explanation and for marking this as an enhancement I would like to see in a future release:-)

Gerrit0 added a commit that referenced this issue Sep 1, 2022
Half of #2030 complete! externalSymbolLinkMappings tomorrow.
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Sep 2, 2022

These docs will be added to the website as well on release - but too late for that tonight, do you think this will meet your use case? https://github.com/TypeStrong/typedoc/blob/master/internal-docs/third-party-symbols.md#third-party-symbols

@danielwiehl
Copy link
Author

These docs will be added to the website as well on release - but too late for that tonight, do you think this will meet your use case? https://github.com/TypeStrong/typedoc/blob/master/internal-docs/third-party-symbols.md#third-party-symbols

@Gerrit0 Great, this is precisely what we were looking for and will cover our use case. Thank you very much!

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Sep 3, 2022

Published! https://typedoc.org/guides/options/#externalsymbollinkmappings

@Gerrit0 Gerrit0 closed this as completed Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality question Question about functionality
Projects
None yet
Development

No branches or pull requests

2 participants