Replies: 1 comment 3 replies
-
I refactored all my models into something like this. export interface IUser {
_version: number;
username: string;
email: string;
password: string;
bets: Array<IBet>; // Instead of IBetDocument = IBet & Types.Subdocument
groupId: Types.ObjectId;
}
export type IUserModel = Model<IUser>;
export const UserSchema = new Schema<IUser, IUserModel>(
{
_version: { type: Number, required: true, default: 1 },
username: { type: String, required: true, unique: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
bets: [{ type: BetSchema, default: [], required: true }],
groupId: { type: Schema.Types.ObjectId, ref: 'group' }
},
{ timestamps: true }
); Now, find queries return const user = await User.findOne({ filter });
// user: (Document<any, any, IGroup> & IGroup & { _id: Types.ObjectId; }) | null Seems more like it, right? But I can also see that |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've noticed that after upgrading to 6.0.7, Model's find methods specify different return types. In 5.x,
UserModel.findOne
would returnIUserDocument
but now it returnsIUserDocument & { _id: any }. I've noticed some changes in the
TypeScript` part of the docs. Does that make my schema & types definitions obsolete?Beta Was this translation helpful? Give feedback.
All reactions