In my MongoDB setup, I have created an interface
that defines a schema using mongoose as an ODM.
import mongoose, { model, Schema, Model, Document } from "mongoose";
import { IUser } from "./user";
import { IPost } from "./posts";
export interface IComment extends Document {
post: IPost;
replyTo: IComment;
owner: IUser;
content: string;
replies: IComment[];
createdAt: Date;
updatedAt: Date;
upvotes: number;
downvotes: number;
}
// ...mongoose schema declaration omitted
Upon compiling Typescript, I encountered the following error:
Type error: Type of property 'replyTo' circularly references itself in mapped type 'LeanDocument<IComment>'.
This issue never occurred when I was using
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2afadaca5adadb1a782f7ecf3f1ecf7">[email protected]</a>
, but I had to upgrade to <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2624252c2424382e0b7d657b37b6578">[email protected]</a>
in order to connect to my serverless instance on Atlas. Downgrading is not an option for me. How can I resolve this circular dependencies issue?