Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3567): correct typing on aggregation out helper #2967

Merged
merged 1 commit into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cursor/aggregation_cursor.ts
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 {
assertUninitialized(this);
this[kPipeline].push({ $out });
return this;
Expand Down
6 changes: 5 additions & 1 deletion test/types/mongodb.test-d.ts
@@ -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