From 8fb901186b7a816e52550c5f9cf4cacd19306fe1 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Fri, 7 Jul 2023 08:37:40 -0600 Subject: [PATCH] Fix duplicate def in type hierarchy Resolves #2327 --- CHANGELOG.md | 4 ++ src/lib/converter/plugins/TypePlugin.ts | 49 +++++++++++++++---------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddce53128..0bf9205e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - Implemented several miscellaneous performance improvements to generate docs faster, this took the time to generate TypeDoc's site from ~5.6 seconds to ~5.4 seconds. +### Bug Fixes + +- Fixed duplicate definitions in type hierarchy when using packages mode, #2327. + ## v0.24.8 (2023-06-04) ### Features diff --git a/src/lib/converter/plugins/TypePlugin.ts b/src/lib/converter/plugins/TypePlugin.ts index 19529ebb4..ee9112edc 100644 --- a/src/lib/converter/plugins/TypePlugin.ts +++ b/src/lib/converter/plugins/TypePlugin.ts @@ -34,7 +34,11 @@ export class TypePlugin extends ConverterComponent { private onRevive(project: ProjectReflection) { for (const id in project.reflections) { - this.resolve(project, project.reflections[id]); + this.resolve( + project, + project.reflections[id], + /* create links */ false + ); } this.finishResolve(project); this.reflections.clear(); @@ -44,7 +48,11 @@ export class TypePlugin extends ConverterComponent { this.resolve(context.project, reflection); } - private resolve(project: ProjectReflection, reflection: Reflection) { + private resolve( + project: ProjectReflection, + reflection: Reflection, + createLinks = true + ) { if (!(reflection instanceof DeclarationReflection)) return; if (reflection.kindOf(ReflectionKind.ClassOrInterface)) { @@ -52,30 +60,31 @@ export class TypePlugin extends ConverterComponent { walk(reflection.implementedTypes, (target) => { this.postpone(target); - if (!target.implementedBy) { - target.implementedBy = []; + target.implementedBy ||= []; + if (createLinks) { + target.implementedBy.push( + ReferenceType.createResolvedReference( + reflection.name, + reflection, + project + ) + ); } - target.implementedBy.push( - ReferenceType.createResolvedReference( - reflection.name, - reflection, - project - ) - ); }); walk(reflection.extendedTypes, (target) => { this.postpone(target); - if (!target.extendedBy) { - target.extendedBy = []; + target.extendedBy ||= []; + + if (createLinks) { + target.extendedBy.push( + ReferenceType.createResolvedReference( + reflection.name, + reflection, + project + ) + ); } - target.extendedBy.push( - ReferenceType.createResolvedReference( - reflection.name, - reflection, - project - ) - ); }); }