Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Inheritance from multiple Partial<T> types was incorrectly conve…
…rted

Resolves #1579.
  • Loading branch information
Gerrit0 committed May 1, 2021
1 parent 58f1bac commit 4aad444
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/lib/models/types/reference.ts
Expand Up @@ -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 ?? []
);
}

/**
Expand Down
23 changes: 22 additions & 1 deletion 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";

Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 4aad444

Please sign in to comment.