How to define mongoose _id in TypeScript interface?
You can extend your interface with mongoose.Document
. Your interface will be come
interface Animal extends mongoose.Document {
name: string;
}
Usage:
export let AnimalSchema = mongoose.model<Animal>('animal', schema, 'animals');
let animal = await AnimalSchema.find({_id: "id"}).exec();
// animal._id / animal.name
you can do this
import { ObjectId } from 'mongoose';
interface Animal {
_id: ObjectId
name: string
}