Recently, I've been transitioning from JavaScript to TypeScript and also upgrading from mongoose 5.8 to version 6.1. The code snippet below used to work perfectly before:
let getActionsTakenByApp = (store_url: string) => {
return AppAction.aggregate([
{
$match: { store_url }
},
{
$group: {
_id: {
'action_type': '$action_type'
},
count: {
$sum: 1
}
}
}
]);
}
However, since the update, TypeScript is now throwing this error:
Type '{ _id: { action_type: string; }; count: { $sum: number; }; }' is not assignable to type '{ [key: string]: { $count?: any; $accumulator?: any; $addToSet?: any; $avg?: any; $first?: any; $last?: any; $max?: any; $mergeObjects?: any; $min?: any; $push?: any; $stdDevPop?: any; $stdDevSamp?: any; $sum?: any; }; _id: any; }'. Property '_id' is incompatible with index signature.
Type '{ action_type: string; }' is not assignable to type '{ $count?: any; $accumulator?: any; $addToSet?: any; $avg?: any; $first?: any; $last?: any; $max?: any; $mergeObjects?: any; $min?: any; $push?: any; $stdDevPop?: any; $stdDevSamp?: any; $sum?: any; }'.
Object literal may only specify known properties, and ''action_type'' does not exist in type '{ $count?: any; $accumulator?: any; $addToSet?: any; $avg?: any; $first?: any; $last?: any; $max?: any; $mergeObjects?: any; $min?: any; $push?: any; $stdDevPop?: any; $stdDevSamp?: any; $sum?: any; }'.ts(2322)
As a TypeScript newcomer, I'm still troubleshooting this issue. Any guidance would be greatly appreciated! Thank you!