diff --git a/.changeset/puny-pets-refuse.md b/.changeset/puny-pets-refuse.md new file mode 100644 index 0000000..5cd6ac4 --- /dev/null +++ b/.changeset/puny-pets-refuse.md @@ -0,0 +1,5 @@ +--- +'starlight-typedoc': patch +--- + +Fixes a potential error when rendering link tags in comments that reference reflections without URLs. diff --git a/fixtures/basics/src/types.ts b/fixtures/basics/src/types.ts index 3d00aba..65da4dc 100644 --- a/fixtures/basics/src/types.ts +++ b/fixtures/basics/src/types.ts @@ -11,3 +11,11 @@ export interface Thing { } export type Things = Thing[] + +export type ThingWithBazAndQuux = Thing & { + baz: string + /** + * @see {@link ThingWithBazAndQuux.baz} + */ + quux: number[] +} diff --git a/packages/starlight-typedoc/libs/theme.ts b/packages/starlight-typedoc/libs/theme.ts index 3bca8ff..edf5f93 100644 --- a/packages/starlight-typedoc/libs/theme.ts +++ b/packages/starlight-typedoc/libs/theme.ts @@ -91,6 +91,11 @@ class StarlightTypeDocThemeRenderContext extends MarkdownThemeContext { (part.tag === '@link' || part.tag === '@linkcode' || part.tag === '@linkplain') && part.target instanceof Reflection ) { + if (!this.router.hasUrl(part.target)) { + const { target, ...rest } = part + return rest + } + return { ...part, target: this.urlTo(part.target), diff --git a/packages/starlight-typedoc/tests/e2e/basics/sidebar.test.ts b/packages/starlight-typedoc/tests/e2e/basics/sidebar.test.ts index 5a1ee48..247d5a5 100644 --- a/packages/starlight-typedoc/tests/e2e/basics/sidebar.test.ts +++ b/packages/starlight-typedoc/tests/e2e/basics/sidebar.test.ts @@ -58,7 +58,7 @@ test('should generate the proper items for for a single entry point', async ({ d }, { label: 'Type Aliases', - items: [{ name: 'Things' }], + items: [{ name: 'Things' }, { name: 'ThingWithBazAndQuux' }], collapsed: true, }, {