I am currently new to MERN and trying to run an application but I have a number of repeating errors in my project starting with this: Property '_id' is optional in type 'CatalogDocumentType' but required in type 'CatalogType', most of my models have these properties, I have no idea what is going on.
this error: Interface 'CatalogDocumentType' cannot simultaneously extend types 'CatalogType' and 'Document'.
Named property '_id' of types 'CatalogType' and 'Document' are not identical.
private async addCatalog(req: Request, res: Response) {
try {
const { code, description, version } = req.body;
const catalog = await this.catalog.findOne({ code }).exec();
if (catalog) return BadRequest(res, 'Catalog code already exists');
const catalogsCatalog = new CatalogModel({
code,
description,
version,
});
const catalogsAdded = await catalogsCatalog.save();
return Ok<CatalogType>(res, catalogsAdded); <-- catalogsAdded sintax error here
} catch (error) {
console.log('error', error);
return ServerError(res);
}
}
export interface CatalogType {
_id: string;
code: string;
description: string;
version: number;
}
export const Model = model<CatalogDocumentType>('Catalog', schema);
Errors:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/sonPw.png
any idea?
question from:
https://stackoverflow.com/questions/65830172/mongoose-typescript-exporting-model-interface-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…