I want to push a message in an array with Mongoose/Mongo. Typescript claims that:
No overload matches this call. Overload 1 of 3, '(id: any, update: UpdateQuery, options: QueryOptions & { rawResult: true; }, callback?: ((err: any, doc: FindAndModifyWriteOpResultObject, res: any) => void) | undefined): any', gave the following error. Type '{ messages: { message: string; authorId: string; }; }' is not assignable to type 'PushOperator<_AllowStringsForIds<Pick<Pick<_LeanDocument, string | number | symbol>, string | number | symbol>>>'. Type '{ messages: { message: string; authorId: string; }; }' is not assignable to type 'NotAcceptedFields<_AllowStringsForIds<Pick<Pick<_LeanDocument, string | number | symbol>, string | number | symbol>>, readonly any[]>'. Property 'messages' is incompatible with index signature.
Here is the code snippet:
const conversation = await Conversation.findByIdAndUpdate(
conversationId,
{
$push: { messages: { message, authorId } },
lastMessage: {
authorId,
snippet: `${message.substring(0, 47)}...`,
read: false,
},
},
{ new: true }
);
The build crash because of this. How to fix it?