I just upgraded to Mongoose 5.12 from 5.11 and am using Typescript. I have this schema
const MyFileSchema = new Schema<IMyFile>({
objectID: { type: String, required: true },
attachments: { type: Array, required: false }
}, { collection: 'my_file' });
Now this findOneAndUpdate is suddenly failing to compile ...
await MyFile.findOneAndUpdate(
{ objectID },
{
$push: {
attachments: { fileName: fileName, id: fileID },
},
},
);
complaining about ...
Type '{ attachments: { fileName: string; id: string; }; }' is not assignable to type 'PushOperator<_AllowStringsForIds<LeanDocument<any>>>'.
Type '{ attachments: { fileName: string; id: string; }; }' is not assignable to type 'NotAcceptedFields<_AllowStringsForIds<LeanDocument<any>>, readonly any[]>'.
Property 'attachments' is incompatible with index signature.
Type '{ fileName: string; id: string; }' is not assignable to type 'undefined'.
Is there another way to write the above to avoid this compilation error that wasn't happening when I was using Mongoose 5.11?