From 3e45d6c4bc97b5479f4fe85affee00c3e2d33575 Mon Sep 17 00:00:00 2001 From: emadum Date: Tue, 20 Jul 2021 14:16:34 -0400 Subject: [PATCH] fix(NODE-3441): fix typings for createIndexes --- src/operations/indexes.ts | 2 +- test/types/mongodb.test-d.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index 6d9bd2fa15..a3a2b91d33 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -70,7 +70,7 @@ export type IndexSpecification = OneOrMore< >; /** @public */ -export interface IndexDescription { +export interface IndexDescription extends CreateIndexesOptions { collation?: CollationOptions; name?: string; key: Document; diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 9bd8c54e70..bd2f5eb019 100644 --- a/test/types/mongodb.test-d.ts +++ b/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'; @@ -32,3 +32,8 @@ const composedMap = mappedAgg.map(x => x.toString()); expectType>(composedMap); expectType(await composedMap.next()); expectType(await composedMap.toArray()); + +// test that VALID_INDEX_OPTIONS like expireAfterSeconds are allowed in IndexDefinitions +coll.createIndexes([{ key: { event: 1 }, name: 'event', expireAfterSeconds: 2400 }]); +// test that invalid options are not allowed +expectError(coll.createIndexes([{ key: { event: 1 }, name: 'event', invalidOption: 2400 }]));