【发布时间】:2021-11-05 01:21:56
【问题描述】:
当我更新到最新的 mongoose 版本 6.0.5 时,使用 $push 更新会出现以下错误。查询和更新仍然有效,当我使用 mongoose 6.0.1 时,我没有收到此错误。
No overload matches this call.
Overload 1 of 3, '(filter: FilterQuery<INotifications>, update: UpdateQuery<INotifications>, options: QueryOptions & { ...; }, callback?: ((err: CallbackError, doc: any, res: any) => void) | undefined): Query<...>', gave the following error.
Type '{ notificationReplyTravaux: IReplyTravaux; }' is not assignable to type 'undefined'.
Overload 2 of 3, '(filter: FilterQuery<INotifications>, update: UpdateQuery<INotifications>, options: QueryOptions & { ...; } & ReturnsNewDoc, callback?: ((err: CallbackError, doc: INotifications, res: any) => void) | undefined): Query<...>', gave the following error.
Type '{ notificationReplyTravaux: IReplyTravaux; }' is not assignable to type 'undefined'.
Overload 3 of 3, '(filter?: FilterQuery<INotifications> | undefined, update?: UpdateQuery<INotifications> | undefined, options?: QueryOptions | null | undefined, callback?: ((err: CallbackError, doc: INotifications | null, res: any) => void) | undefined): Query<...>', gave the following error.
Type '{ notificationReplyTravaux: IReplyTravaux; }' is not assignable to type 'undefined'.ts(2769)
index.d.ts(2588, 5): The expected type comes from property '$push' which is declared here on type 'UpdateQuery<INotifications>'
index.d.ts(2588, 5): The expected type comes from property '$push' which is declared here on type 'UpdateQuery<INotifications>'
(property) $push?: undefined
架构
import mongoose, { PopulatedDoc } from 'mongoose';
import { IArchivedOrder } from './ArchivedOrders.model';
import { IReplyTravaux } from './ReplyTravaux.model';
export interface INotifications extends mongoose.Document {
user: string,
notificationReplyTravaux: PopulatedDoc<IReplyTravaux & Document>[],
notificationOrder: PopulatedDoc<IArchivedOrder & Document>[],
}
const NotificationsSchema = new mongoose.Schema<INotifications>({
user: String,
notificationReplyTravaux: [
{
type: String,
ref: 'ReplyTravaux',
},
],
notificationOrder: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'ArchivedOrders',
},
],
});
export default mongoose.model<INotifications>('Notification', NotificationsSchema);
IRplyTravaux 界面
export interface IReplyTravaux extends mongoose.Document {
_id: string,
message: string,
author: {
id: string,
name: string,
},
travaux: string | ITravaux,
createdAt: Date,
}
【问题讨论】:
标签: node.js typescript mongodb mongoose