Typescript error when working with mongoose ( running inside kubernetes cluster and skaffold ) Typescript error when working with mongoose ( running inside kubernetes cluster and skaffold ) kubernetes kubernetes

Typescript error when working with mongoose ( running inside kubernetes cluster and skaffold )


I think this could help

First you have to create 3 interfaces.

interface UserAttrs {  email: string;  password: string;}interface UserModel extends mongoose.Model<UserDoc> {  build(attrs: UserAttrs): UserDoc;}interface UserDoc extends mongoose.Document {  email: string;  password: string; }

Then in your schema's middleware you have to declare the type of the variables that you're using

userSchema.pre("save", async function (this: UserDoc, next: any) {  if (this.isModified("password")) {    const hashed = await Password.toHash(this.get("password"));    this.set("password", hashed);  }  next();});const User = mongoose.model<UserDoc, UserModel>('User', userSchema);

Related issue that I found