From 4aad444e7995719f2988346e0e1bc6a836f48c20 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 1 May 2021 14:35:02 -0600 Subject: [PATCH] fix: Inheritance from multiple Partial types was incorrectly converted Resolves #1579. --- src/lib/models/types/reference.ts | 24 ++++++++++++++++++------ src/test/models/types/reference.test.ts | 23 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/lib/models/types/reference.ts b/src/lib/models/types/reference.ts index 15805c723..f6421b28c 100644 --- a/src/lib/models/types/reference.ts +++ b/src/lib/models/types/reference.ts @@ -87,13 +87,25 @@ export class ReferenceType extends Type { * @returns TRUE if the given type equals this type, FALSE otherwise. */ equals(other: ReferenceType): boolean { - if (other instanceof ReferenceType) { - if (this.reflection != null) { - return this.reflection === other.reflection; - } - return this._target === other._target; + if (!(other instanceof ReferenceType)) { + return false; } - return false; + + let matchesTarget; + if (!this.reflection) { + matchesTarget = this._target === other._target; + } else { + matchesTarget = this.reflection === other.reflection; + } + + if (!matchesTarget) { + return false; + } + + return Type.isTypeListEqual( + this.typeArguments ?? [], + other.typeArguments ?? [] + ); } /** diff --git a/src/test/models/types/reference.test.ts b/src/test/models/types/reference.test.ts index 23382e2ff..b903dcf63 100644 --- a/src/test/models/types/reference.test.ts +++ b/src/test/models/types/reference.test.ts @@ -1,6 +1,10 @@ import type * as ts from "typescript"; import { deepStrictEqual as equal } from "assert"; -import { ProjectReflection, ReflectionKind } from "../../../lib/models"; +import { + LiteralType, + ProjectReflection, + ReflectionKind, +} from "../../../lib/models"; import { DeclarationReflection } from "../../../lib/models/reflections/declaration"; import { ReferenceType } from "../../../lib/models/types/reference"; @@ -45,5 +49,22 @@ describe("Reference Type", () => { equal(type1.equals(type2), true); }); + + it("types with the same type parameters are equal", () => { + const type1 = new ReferenceType("Type1", reflection, project); + type1.typeArguments = [new LiteralType(null)]; + const type2 = new ReferenceType("Type2", fakeSymbol1, project); + type2.typeArguments = [new LiteralType(null)]; + + equal(type1.equals(type2), true); + }); + + it("types with different type parameters are not equal", () => { + const type1 = new ReferenceType("Type1", reflection, project); + type1.typeArguments = [new LiteralType(null)]; + const type2 = new ReferenceType("Type2", fakeSymbol1, project); + + equal(type1.equals(type2), false); + }); }); });