diff --git a/test/types/models.test.ts b/test/types/models.test.ts index bbfbc1517cf..c9b9c244422 100644 --- a/test/types/models.test.ts +++ b/test/types/models.test.ts @@ -771,3 +771,21 @@ function gh13897() { expectType(doc.createdAt); expectError(new Document({ name: 'foo' })); } + +async function gh14026() { + interface Foo { + bar: string[]; + } + + const FooModel = mongoose.model('Foo', new mongoose.Schema({ bar: [String] })); + + const distinctBar = await FooModel.distinct('bar'); + expectType(distinctBar); + + const TestModel = mongoose.model( + 'Test', + new mongoose.Schema({ bar: [String] }) + ); + + expectType(await TestModel.distinct('bar')); +} diff --git a/types/models.d.ts b/types/models.d.ts index 2a2bb0ff334..6772901e66d 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -481,7 +481,7 @@ declare module 'mongoose' { field: DocKey, filter?: FilterQuery ): QueryWithHelpers< - Array, + Array : ResultType>, THydratedDocumentType, TQueryHelpers, TRawDocType, diff --git a/types/query.d.ts b/types/query.d.ts index 008f82d2d9d..e66a7c9a2f4 100644 --- a/types/query.d.ts +++ b/types/query.d.ts @@ -320,7 +320,7 @@ declare module 'mongoose' { distinct( field: DocKey, filter?: FilterQuery - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'distinct'>; + ): QueryWithHelpers : ResultType>, DocType, THelpers, RawDocType, 'distinct'>; /** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */ elemMatch(path: K, val: any): this;