【发布时间】:2021-10-30 13:38:58
【问题描述】:
我有这个 interface 在我的 MongoDB 中定义一个架构,我在其中使用 mongoose 作为 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
当我尝试编译 Typescript 时,我得到了这个:
Type error: Type of property 'replyTo' circularly references itself in mapped type 'LeanDocument<IComment>'.
这在我使用 mongoose@5.13.5 时从未发生过,但我必须升级到 mongoose@6.0.3 才能连接到 Atlas 上的无服务器实例。我不认为降级是一种选择。如何解决此循环依赖问题?
【问题讨论】:
标签: typescript mongodb mongoose next.js