Skip to content

Commit 3a55cc2

Browse files
committed
Only treat symbols as external if all declarations are external
Ref: #2844
1 parent f7aa8bd commit 3a55cc2

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ title: Changelog
1515
- Fixed an issue where TypeDoc would incorrectly ignore type arguments in references, #2823.
1616
- Improved narrator support for labeling icons, #2832.
1717
- Fixed an issue with `@class` incorrectly handling mapped types, #2842.
18+
- TypeDoc will now consider symbols to be external only if all of their declarations are external
19+
so that declaration merged members with global symbols can be documented, #2844.
1820

1921
### Thanks!
2022

src/lib/converter/converter.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,19 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
621621
this.externalPatternCache ??= createMinimatch(this.externalPattern);
622622
const cache = this.externalPatternCache;
623623

624-
return (symbol.getDeclarations() ?? []).some((node) =>
624+
const declarations = symbol.getDeclarations();
625+
626+
// `undefined` has no declarations, if someone does `export default undefined`
627+
// the symbol ends up as having no declarations (the export symbol does, but
628+
// not the source symbol)
629+
if (!declarations?.length) {
630+
return false;
631+
}
632+
633+
// If there are any non-external declarations, treat it as non-external
634+
// This is possible with declaration merging against external namespaces
635+
// (e.g. merging with HTMLElementTagNameMap)
636+
return declarations.every((node) =>
625637
matchesAny(cache, node.getSourceFile().fileName),
626638
);
627639
}

src/test/converter2/issues/gh2844.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export {};
2+
3+
declare global {
4+
namespace globalThis {
5+
interface URL {
6+
customMethod(): string;
7+
}
8+
}
9+
}

src/test/issues.c2.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2022,4 +2022,14 @@ describe("Issue Tests", () => {
20222022
equal(hello.kind, ReflectionKind.Property);
20232023
equal(hello.type?.toString(), "string");
20242024
});
2025+
2026+
it("#2844 treats partially-external symbols as not external", () => {
2027+
app.options.setValue("excludeExternals", true);
2028+
const project = convert();
2029+
const url = query(project, "globalThis.URL");
2030+
equal(
2031+
url.children?.map((c) => c.name),
2032+
["customMethod"],
2033+
);
2034+
});
20252035
});

0 commit comments

Comments
 (0)