Mongoose ObjectId not matched in typescript

Viewed 477

I defined an interface using mongoose.

import {Types} from 'mongoose'    

export interface IShop {  
  readonly center: Types.ObjectId;    
}


async create(data):Promise<IShop>{
   const result = await new this.model(data).save
   return result
}

And there is a shcema as below.

 {
   center: mongoose.Schema.Types.ObjectId
 }

But this gives an error of type saying

Error:(18, 5) TS2322: Types of property 'center' are incompatible. Type 'ObjectId' is missing the following properties from type 'ObjectId': generationTime, equals, getTimestamp, toHexString

But when I define mongoose.Schema.Types.ObjectId in interface it matches well. But I have to use Types.ObjectId for making new Types.ObjectId(string) in somewhere.

Could you help me some advice for this?

I use mongoose 5.11.9 and I dont' use @types/mongoose.

0 Answers
Related