Skip to content

Commit

Permalink
Merge pull request #13718 from Automattic/vkarpov15/gh-13702
Browse files Browse the repository at this point in the history
types(schema): correct return type for `Schema.prototype.indexes()`
  • Loading branch information
vkarpov15 committed Aug 10, 2023
2 parents 35d0978 + 56dfead commit a88b73f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexDefinition>;
indexes(): Array<[IndexDefinition, IndexOptions]>;

/** Gets a schema option. */
get<K extends keyof SchemaOptions>(key: K): SchemaOptions[K];
Expand Down

0 comments on commit a88b73f

Please sign in to comment.