dsanel / mongoose-delete

Mongoose Soft Delete Plugin
MIT License
346 stars 101 forks source link

Generic type 'SoftDeleteModel<T, QueryHelpers>' requires between 1 and 2 type arguments. #125

Closed durveshparmar closed 1 year ago

durveshparmar commented 2 years ago

Hi All,

I am trying to use this plugin in node typescript and I am facing error message as per the title which is as following.

"[{
    "resource": "xxx.model.ts",
    "owner": "typescript",
    "code": "2707",
    "severity": 8,
    "message": "Generic type 'SoftDeleteModel<T, QueryHelpers>' requires between 1 and 2 type arguments.",
    "source": "ts",
}]"

CODE Is as Following:

const exampleSchema= new mongoose.Schema({
    title: { type: String, required: true },
  },  {
    timestamps: true,
  }
);

exampleSchema.plugin(MongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all', indexFields: ['deleted'] });

const ExampleModel: SoftDeleteModel = mongoose.model<ExampleDocument>("Example", exampleSchema);

Package Versions: "mongodb": "^4.4.1", "mongoose": "^6.2.9", "mongoose-delete": "^0.5.4", "@types/mongoose-delete": "^0.5.9",

Please let me know what should be the solution in this case.

Thanks and regards.

riccox commented 2 years ago

my suggestion : i guess the document type should be wrapped by HydratedDocument like this:

const ExampleModel: SoftDeleteModel<HydratedDocument<Your-Interface>> = mongoose.model("Example", exampleSchema);
durveshparmar commented 2 years ago

I will try this one and update here. Thanks for your response though