Skip to content

Commit a299a0b

Browse files
authored
fix(NODE-3567): correct typing on aggregation out helper (#2967)
1 parent 319f8ae commit a299a0b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/cursor/aggregation_cursor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
120120
return this;
121121
}
122122

123-
/** Add a out stage to the aggregation pipeline */
124-
out($out: number): this {
123+
/** Add an out stage to the aggregation pipeline */
124+
out($out: string): this {
125125
assertUninitialized(this);
126126
this[kPipeline].push({ $out });
127127
return this;

test/types/mongodb.test-d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectType, expectDeprecated } from 'tsd';
1+
import { expectType, expectDeprecated, expectError } from 'tsd';
22
import { MongoClient } from '../../src/mongo_client';
33
import { Collection } from '../../src/collection';
44
import { AggregationCursor } from '../../src/cursor/aggregation_cursor';
@@ -35,3 +35,7 @@ const composedMap = mappedAgg.map<string>(x => x.toString());
3535
expectType<AggregationCursor<string>>(composedMap);
3636
expectType<string | null>(await composedMap.next());
3737
expectType<string[]>(await composedMap.toArray());
38+
39+
const builtCursor = coll.aggregate();
40+
expectType<AggregationCursor<Document>>(builtCursor.out('string')); // should allow string values for the out helper
41+
expectError(builtCursor.out(1)); // should error on non-string values

0 commit comments

Comments
 (0)