Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
>=8.0.2
Node.js version
20
MongoDB server version
Not needed
Typescript version (if applicable)
5.3.3
Description
I was updating Mongoose and found all the prop values of the schema types became unknown
so I tried to check previous versions and found it's starting from 8.0.2
, after checking commits and reverting them, and found this pr is causing the issue. It happens when the array of objects has a type
as a prop, and also if the schema has a prop with the value SchemaTypes.Array
. Using new Schema for subdocument fixes this but causes another issue with lean type for arrays, will create a new issue for that
Steps to Reproduce
export const UserSchema = new Schema(
{
reminders: {
type: [
{
type: { type: SchemaTypes.String },
date: { type: SchemaTypes.Date },
toggle: { type: SchemaTypes.Boolean },
notified: { type: SchemaTypes.Boolean },
},
],
default: [
{ type: 'vote', date: new Date(), toggle: false, notified: false },
{ type: 'daily', date: new Date(), toggle: false, notified: false },
{ type: 'drop', date: new Date(), toggle: false, notified: false },
{ type: 'claim', date: new Date(), toggle: false, notified: false },
{ type: 'work', date: new Date(), toggle: false, notified: false },
],
},
avatar: {
type: SchemaTypes.String,
},
},
{ timestamps: true },
);
export type IUser = InferSchemaType<typeof UserSchema>;
Lemme know if I'm doing anything wrong with the schema. Or if it's a bug, I'll be happy to contribute, lemme me know how can I fix it.
Expected Behavior
It should give proper typings like before
_Originally posted by @imranbarbhuiya in #14095 (comment)