I was gonna use statics in mongoose with typescript but typescript does not understand this static.
I found the type definition from website and it said like this
import { Document, model, Model, Schema } from "mongoose";
var UserSchema = new Schema({});
UserSchema.statics.static1 = function () {
return "";
};
interface IUserDocument extends Document {}
interface IUserModel extends Model<IUserDocument> {
static1: () => string;
}
var UserModel: IUserModel = model<IUserDocument, IUserModel>(
"User",
UserSchema
);
UserModel.static1(); // static methods are available
yes it worked before I set something in the Document{}
import { Document, model, Model, Schema } from "mongoose";
var UserSchema = new Schema({
name: {
type: String,
maxlength: 50,
},
});
UserSchema.statics.static1 = function () {
return "";
};
interface IUserDocument extends Document {
name: string;
}
interface IUserModel extends Model<IUserDocument> {
static1: () => string;
}
var UserModel: IUserModel = model<IUserDocument, IUserModel>(
"User",
UserSchema
);
UserModel.static1(); // Property 'static1' is missing in type 'Model<IUserDocument>' but required in type 'IUserModel'
I don't know why this weird problem occurred... please help me