title: Solved - Mongoose and typescript how can i update the data?
body: <p>I have an interface like this.</p>
  <pre><code>export interface IMerchant{
      id?:string,
      name:string,
      surname:string,
      mail:string,
  }
  </code></pre>
  <p>My schema like this</p>
  <pre><code>    import { Schema, model, Model } from 'mongoose';
  
      interface IMerchantModel extends Model&lt;IMerchant&gt; {
          getAllMerchants(): IMerchant[];
          setMerchant(merchant:IMerchant):IMerchant;
      }
      
      const merchantSchema = new Schema&lt;IMerchant, IMerchantModel&gt;({
          name: { type: String, required: true },
          surname:{type:String,required:true},
          mail:{type:String,required:true},
      },
      {
          timestamps: { createdAt: &quot;createdDate&quot;, updatedAt: &quot;updatedDate&quot; },
          toJSON: { virtuals: true },
      });
  
      const Merchant = model&lt;IMerchant, IMerchantModel&gt;('Merchant', merchantSchema);
      export default Merchant;
  </code></pre>
  <p>My main goal is create a data if not exist or update it if exist.</p>
  <pre><code>merchantSchema.static('setMerchant', async function setMerchant(merchant:IMerchant) {
      try{
          if(merchant.id){
              // if object has id field get from collection.
              let m = await this.findOne({ id: merchant.id }) as IMerchant;
              if (m) {
                 m={...merchant};
                 m.save();
                 //Error -&gt; Property 'save' does not exist on type 'IMerchant'.
              }
              return m;
          }
          else{
              // if not exist, create one
              const newData= new Merchant(merchant);
              const savedData=await newData.save();
              return savedData;
          }
      }
      catch(e){
          // throw an Error
      }
  });
  </code></pre>
  <p>So main problem in update I got an error.</p>
  <blockquote>
  <p>Property 'save' does not exist on type 'IMerchant'.</p>
  </blockquote>
  <p>How can I cast return data from findOne</p>