I answered a very similar question here , although I will answer yours (basically the third section of my other answer), since you provided a different scheme. There is a useful readme with typical Mongoose types that are pretty hidden, but there is a section on static methods .
The behavior you described is completely normal - Typescript reports that the schema (an object that describes individual documents) has a method called getLiveCampaigns .
Instead, you need to tell Typescript that the method is on the model, not on the diagram. After that, you can access the static methods according to the regular Mongoose method. You can do it as follows:
// CampaignDocumentInterface should contain your schema interface, // and should extend Document from mongoose. export interface CampaignInterface extends CampaignDocumentInterface { // declare any instance methods here } // Model is from mongoose.Model interface CampaignModelInterface extends Model<CampaignInterface> { // declare any static methods here getLiveCampaigns(): any; // this should be changed to the correct return type if possible. } export const CampaignSchema = new Schema({ title: { type: String, required: true }, titleId: { type: String, required: true } // ...etc )} CampaignSchema.statics.getLiveCampaigns = Promise.method(function (){ const now: Date = new Date() return this.find({ $and: [{startDate: {$lte: now} }, {endDate: {$gte: now} }] }).exec() }) // Note the type on the variable, and the two type arguments (instead of one). const Campaign: CampaignModelInterface = mongoose.model<CampaignInterface, CampaignModelInterface>('Campaign', CampaignSchema) export default Campaign
source share