Skip to content

Commit

Permalink
fix(NODE-3567): correct typing on aggregation out helper (#2967)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum authored Sep 1, 2021
1 parent 319f8ae commit a299a0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cursor/aggregation_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
return this;
}

/** Add a out stage to the aggregation pipeline */
out($out: number): this {
/** Add an out stage to the aggregation pipeline */
out($out: string): this {

This comment has been minimized.

Copy link
@Loksly

Loksly Sep 2, 2021

Hi Eric,
string is not the only valid type. As I reported
$out can also be an object check the doc

This comment has been minimized.

Copy link
@emadum

emadum Sep 2, 2021

Author Contributor

Oops thanks for catching that! I filed #2971 to address this oversight.

assertUninitialized(this);
this[kPipeline].push({ $out });
return this;
Expand Down
6 changes: 5 additions & 1 deletion test/types/mongodb.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectType, expectDeprecated } from 'tsd';
import { expectType, expectDeprecated, expectError } from 'tsd';
import { MongoClient } from '../../src/mongo_client';
import { Collection } from '../../src/collection';
import { AggregationCursor } from '../../src/cursor/aggregation_cursor';
Expand Down Expand Up @@ -35,3 +35,7 @@ const composedMap = mappedAgg.map<string>(x => x.toString());
expectType<AggregationCursor<string>>(composedMap);
expectType<string | null>(await composedMap.next());
expectType<string[]>(await composedMap.toArray());

const builtCursor = coll.aggregate();
expectType<AggregationCursor<Document>>(builtCursor.out('string')); // should allow string values for the out helper
expectError(builtCursor.out(1)); // should error on non-string values

0 comments on commit a299a0b

Please sign in to comment.