如何解决Mongoose + Typescript -> 导出模型接口错误
我目前是 MERN 的新手并试图运行一个应用程序,但我的项目中有许多重复的错误,从这个开始:属性 '_id' 在类型 'CatalogDocumentType' 中是可选的,但在类型 'CatalogType' 中是必需的,大多数我的模型有这些属性,我不知道发生了什么。
此错误:接口“CatalogDocumentType”无法同时扩展类型“CatalogType”和“Document”。 “CatalogType”和“Document”类型的命名属性“_id”不相同。
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,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
有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。