You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.4.1
Node.js version
16.13.0
MongoDB server version
5.0
Description
Basically, I took the example from the docs and pluralized property name. The reslulting schema type is inferred as { ..., names?: unknown[] | undefined }.
The same thing happens when using a nested document, names: new Schema({}) and when using names: {type: [{...}]} the only array type which seems to be inferred correctly are primitive types e.g. names: [String] is inferred correctly as string[]
Steps to Reproduce
constschema=newmongoose.Schema({names: [{type: String,required: true}],email: {type: String,required: true},avatar: String,});typeUser=InferSchemaType<typeofschema>;// InferSchemaType will determine the type as follows:// type User = {// email: string;// avatar?: string | undefined;// names?: unknown[] | undefined;// };
Expected Behavior
constschema=newmongoose.Schema({names: [{type: String,required: true}],email: {type: String,required: true},avatar: String,});typeUser=InferSchemaType<typeofschema>;// InferSchemaType will determine the type as follows:// type User = {// email: string;// avatar?: string | undefined;// name: string[] | undefined;// };
The text was updated successfully, but these errors were encountered:
Yeah, you're right @heilmela ... I'm about to push a commit to fix that in the PR I've linked above. It should allow defining schema paths like this as well.
names: [{type: String,required: true}],
The only issue is, that it'll match the string type but not make it required.
Prerequisites
Mongoose version
6.4.1
Node.js version
16.13.0
MongoDB server version
5.0
Description
Basically, I took the example from the docs and pluralized property
name
. The reslulting schema type is inferred as{ ..., names?: unknown[] | undefined }
.The same thing happens when using a nested document,
names: new Schema({})
and when usingnames: {type: [{...}]}
the only array type which seems to be inferred correctly are primitive types e.g.names: [String]
is inferred correctly as string[]Steps to Reproduce
Expected Behavior
The text was updated successfully, but these errors were encountered: