-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
No transpilation error.
If the current behavior is a bug, please provide the steps to reproduce.
There are 2 scenarios that should be fixed. For both scenarios I define the following Schema:
const RoleSchema: Schema = new Schema({
assignments: {
type: Schema.Types.Number,
required: true,
}
});
Scenario 1
class Role {
assignments: number;
}
const roleModel: Model<Document<Role>> = model<Document<Role>>('roles', RoleSchema);
roleModel.find({ assignments: 'xxx' }); // <-- This line does not throw a transpilation error even though a string is not assignable to a number
Scenario 2
class Role {
assignments: number;
}
const roleModel: Model<Document<Role>> = model<Document<Role>>('roles', RoleSchema);
roleModel.find({ assignments2: 2 }); // <-- This line does not throw a transpilation error even though property "assignments2" does not exist on class "Role"
What is the expected behavior?
Both scenarios should produce a transpilation error.
Additional info: After some debugging I noticed that Scenario 1 is behaving correctly when extending Document
. Example:
class RoleDocument extends Document {
assignee: number;
}
const roleModel: Model<RoleDocument> = model('roles', RoleSchema);
roleModel.find({ assignee: 'XXX' }); // <-- Produces TS error "Type 'string' is not assignable to type 'Condition<number>'"
I would expect the same behaviour when using Model<Document<Role>>
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS: v12.13.0
Mongoose: v5.11.9
Metadata
Metadata
Assignees
Labels
No labels