From 56dfead98b02956fe26acb2a7f957c9c26effe8a Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 10 Aug 2023 10:59:27 -0400 Subject: [PATCH] types(schema): correct return type for `Schema.prototype.indexes()` Fix #13702 --- test/types/schema.test.ts | 23 +++++++++++++++-------- types/index.d.ts | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 52ac2229e3a..04bd64a72a3 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -1,19 +1,21 @@ import { Schema, Document, + HydratedDocument, + IndexDefinition, + IndexOptions, + InferSchemaType, + InsertManyOptions, + ObtainDocumentType, + ObtainSchemaGeneric, + ResolveSchemaOptions, SchemaDefinition, SchemaTypeOptions, Model, - Types, - InferSchemaType, SchemaType, + Types, Query, - model, - HydratedDocument, - ResolveSchemaOptions, - ObtainDocumentType, - ObtainSchemaGeneric, - InsertManyOptions + model } from 'mongoose'; import { expectType, expectError, expectAssignable } from 'tsd'; import { ObtainDocumentPathType, ResolvePathType } from '../../types/inferschematype'; @@ -1170,3 +1172,8 @@ function gh13633() { expectType<(InsertManyOptions & { lean?: boolean }) | undefined>(options); }); } + +function gh13702() { + const schema = new Schema({ name: String }); + expectType<[IndexDefinition, IndexOptions][]>(schema.indexes()); +} diff --git a/types/index.d.ts b/types/index.d.ts index 10bfe490da4..95653baf5a4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -278,7 +278,7 @@ declare module 'mongoose' { * Returns a list of indexes that this schema declares, via `schema.index()` * or by `index: true` in a path's options. */ - indexes(): Array; + indexes(): Array<[IndexDefinition, IndexOptions]>; /** Gets a schema option. */ get(key: K): SchemaOptions[K];