Using a pipeline in $unionWith throws a Typescript error.
Example:
const data = model.aggregate([
{
$match: {
somevalue: "string"
}
},
{
$unionWith: {
coll: "some.collection",
pipeline: [
{
$match: {
someField: "someValue"
}
}
]
}
}
]);
Error:
Type '{ $match: { someField: string; }; }[]' is not assignable to type 'AddFields | Bucket | BucketAuto | CollStats | Count | Facet | GeoNear | GraphLookup | Group | ... 20 more ... | undefined'.
Property '$unwind' is missing in type '{ $match: { someField: string; }; }[]' but required in type 'Unwind'.ts(2322)
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./bin",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": [
"**/__tests__/*.test.ts",
]
}
Code sandbox: https://codesandbox.io/s/admiring-tree-pjlze?file=/src/index.ts:96-361
The problem seems to be that the declaration of pipeline type is not an array.
|
export interface UnionWith { |
|
/** [`$unionWith` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/) */ |
|
$unionWith: |
|
| string |
|
| { coll: string; pipeline?: Exclude<PipelineStage, PipelineStage.Out | PipelineStage.Merge> } |
|
} |
Using a pipeline in
$unionWiththrows a Typescript error.Example:
Error:
tsconfig.json
Code sandbox: https://codesandbox.io/s/admiring-tree-pjlze?file=/src/index.ts:96-361
The problem seems to be that the declaration of
pipelinetype is not an array.mongoose/index.d.ts
Lines 3176 to 3181 in 61ad24d