-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema definition does not accept Schema instance as a value #9862
Comments
Update: const ProfileSchema = new Schema<ProfileDoc>(ProfileSchemaDef); to const ProfileSchema = new Schema<ProfileDoc, any>(ProfileSchemaDef); and now the |
One more update: const ProfileSchema = new Schema(ProfileSchemaDef); This seems like a much more ideal solution. However, I still think the the original form of the definition should work, since |
Part of the issue is that the type of import { Document, Schema, SchemaDefinition, Model } from "mongoose";
interface IProfile {
age: Number;
}
interface ProfileDoc extends Document, IProfile {}
interface IUser {
email: string;
profile: ProfileDoc; // <-- changed
}
interface UserDoc extends Document, IUser {};
const ProfileSchemaDef: SchemaDefinition<IProfile> = {
age: Schema.Types.Number
};
const ProfileSchema = new Schema<ProfileDoc, Model<ProfileDoc>, ProfileDoc>(ProfileSchemaDef); // <-- added generics
const UserSchemaDef: SchemaDefinition<IUser> = {
email: String,
profile: ProfileSchema
}; |
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
Here is the sample code
This code gives me the following error on the
profile: ProfileSchema
lineHowever if I change it to
profile: ProfileSchemaDef
, the error goes away.I looked into mongoose's .d.ts file, and it looks like the
SchemaDefinitionProperty
type is correctly expecting aSchema
type. But when I give it a Schema instance, it fails. So I have to resort to providing aSchemaDefinition<T>
instance.If the current behavior is a bug, please provide the steps to reproduce.
Code provided above.
What is the expected behavior?
profile: ProfileSchema
should not result in errors.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v12.15.0, mongoose v5.11.11
The text was updated successfully, but these errors were encountered: