我正在嘗試回傳貓鼬檔案,但隨后出現此錯誤:
型別“(IPersonDocument & { _id: ObjectId; })[]”缺少型別“IPersonDocument”中的以下屬性:firstName、lastName、groups、$assertPopulated 和 52 more.ts(2740)
IPersonDocument 是擴展IPerson和Mongoose.Document
這是我的代碼:
報告.ts
export async function findByName(name: String): Promise<IPersonDocument>{
return await PersonsModel.find({ firstName: name }) //problem here
}
型別.ts
import { Document, Model } from "mongoose";
export interface IPerson {
firstName: string;
lastName: string;
age?: number;
email?: string,
groups: [String],
dateOfEntry?: Date;
}
export interface IPersonDocument extends IPerson, Document { }
export interface IPersonModel extends Model<IPersonDocument> { }
模塊.ts
import { model } from "mongoose";
import { IPersonDocument } from "../../../type/person.types";
import PersonsSchema from "./person.schema";
export const PersonsModel = model<IPersonDocument>("persons", PersonsSchema)
uj5u.com熱心網友回復:
添加精益()
return await PersonsModel.find({ firstName: name }).lean();
它將 DOC 物件轉換為 js 物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537072.html
標籤:打字稿猫鼬
上一篇:在django表單的后臺保存客戶
