TypeScript Duplicate Property Signature Error in Abstract Base Entity Class

im getting a Duplicate property signature "id" error when running my test. I have a an abstract base Entity class that has specific equality logic i want all child classes to inherit. This equality logic is predicated on an 'id' property that can either be string or number that i leave up to the inheriting class to decide. If i omit the Schema.Class extension with a generic protected property id, the tests pass. but i can't extend from multiple classes so im forced to choose between Schema.Class or vanilla abstract classes...

import * as S from "@effect/schema/Schema";
import { Equal, Hash } from "effect";

export abstract class Entity extends S.Class<Entity>("@modules/common/models/entity")({
  id: S.Union(S.NonEmpty, S.Int.pipe(S.positive())),
}) {
  [Hash.symbol](): number {
    return Hash.hash(this.id);
  }

  [Equal.symbol](that: unknown): boolean {
    if (that instanceof Entity) {
      return (
        Equal.equals(that.constructor.name, this.constructor.name) &&
        Equal.equals(typeof that.id, typeof this.id) &&
        Equal.equals(that.id, this.id)
      );
    }
    return false;
  }
}

the test thats triggering the error

import { Schema } from "@effect/schema";
import { Equal } from "effect";
import { describe, expect, it } from "vitest";
import { Entity } from "./entity";

class Supplier extends Entity.extend<Supplier>("Supplier")({
  id: Schema.NonEmpty,
}) {}

class Product extends Entity.extend<Product>("Product")({}) {}

const supplierA = new Supplier({ id: "foo" });
const supplierB = new Supplier({ id: "foo" });
const supplierC = new Supplier({ id: "bar" });
const productA = new Product({ id: "foo" });

describe("entity", () => {
  it("handles equality between entities correctly", () => {
    expect(Equal.equals(supplierA, supplierB)).toBeTruthy();
    expect(Equal.equals(supplierB, supplierC)).toBeFalsy();
    expect(Equal.equals(supplierA, productA)).toBeFalsy();
  });
});
Was this page helpful?