I am looking to integrate mongoose
with TypeScript
and also want to enhance Model functionality by adding a new method.
However, when I try to transpile the file using tsc, I encounter the following error:
spec/db/models/match/matchModelSpec.ts(47,36): error TS2339: Property
'findLeagueMatches' does not exist on type 'Model<MatchModelI>'.
Here is the code from MatchModel.ts:
import {MatchInterface} from "./matchInterface";
import {Schema, model, Model, Document} from "mongoose";
export interface MatchModelI extends MatchInterface, Document {
findLeagueMatches(locationName: String, leagueName: String): Promise<MatchModelI[]>;
}
export let matchSchema: Schema = new Schema({
startTime: {type: Date, required: true},
location: {type: Schema.Types.ObjectId, ref: 'Location'},
league: {type: Schema.Types.ObjectId, ref: 'League'}
});
matchSchema.methods.findLeagueMatches = function(locationName: String, leagueName: String){
//...
return matches;
};
export const Match: Model<MatchModelI> = model<MatchModelI>("Match", matchSchema);