-
-
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
Missing TypeScript type definition for "pre and post middleware remove '' method #13518
Comments
I apologize for not realizing that the 'remove' method is deprecated in the current version. |
Yeah |
@vkarpov15 Should the schema.post('remove', function(doc) {
console.log('%s has been removed', doc._id);
}); When use it with TS, TSC will throw an error: o overload matches this call.
The last overload gave the following error.
Argument of type '"remove"' is not assignable to parameter of type 'RegExp | "insertMany"'.ts(2769) |
@mrdulin nope, that documentation looks correct. Might be a TypeScript issue, will have to check |
Am able to get same error message import { Schema, model, connect } from 'mongoose';
// 1. Create an interface representing a document in MongoDB.
interface IUser {
name: string;
email: string;
avatar?: string;
}
// 2. Create a Schema corresponding to the document interface.
const userSchema = new Schema<IUser>({
name: { type: String, required: true },
email: { type: String, required: true },
avatar: String
});
userSchema.pre('remove', function(doc) {
console.log('the doc', doc);
});
// 3. Create a Model.
const User = model<IUser>('User', userSchema);
run().catch(err => console.log(err));
async function run() {
// 4. Connect to MongoDB
await connect('mongodb://127.0.0.1:27017/test');
const user = new User({
name: 'Bill',
email: 'bill@initech.com',
avatar: 'https://i.imgur.com/dM7Thhn.png'
});
await user.save();
console.log(user.email); // 'bill@initech.com'
} |
docs(middleware): fix old example using `post('remove')`
Prerequisites
Mongoose version
7.1.0
Node.js version
20.3.0
MongoDB server version
6.0.6
Typescript version (if applicable)
5.0.4
Description
I have noticed that there is a missing TypeScript type definition for the 'pre middleware remove' method in Mongoose.
It show's this error
Eg:
Steps to Reproduce
By following these steps, you should be able to reproduce the problem of the missing TypeScript type definition for the pre middleware remove method in Mongoose.
Expected Behavior
pre
method and its arguments, including theremove
hook.The text was updated successfully, but these errors were encountered: