Skip to content

Commit c6bd5c3

Browse files
Refactor statics & methods props in SchemaOptions.
1 parent 2332068 commit c6bd5c3

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

test/types/document.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ function m0_0aDocument() {
183183
/* Document-Methods-tests */
184184
/* -------------------------------------------------------------------------- */
185185

186-
expectType<ReturnType<M0_0aAutoTypedSchemaType['methods']['instanceFn']>>(AutoTypeModelInstance.instanceFn());
186+
expectType<ReturnType<M0_0aAutoTypedSchemaType['methods']['instanceFn']>>(new AutoTypedModel().instanceFn());
187187

188188
}

test/types/schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Schema, Document, SchemaDefinition, Model, Types, InferSchemaType, SchemaType, Query } from 'mongoose';
1+
import { Schema, Document, SchemaDefinition, Model, Types, InferSchemaType, SchemaType, Query, HydratedDocument } from 'mongoose';
22
import { expectType, expectError, expectAssignable } from 'tsd';
33

44
enum Genre {
@@ -445,7 +445,7 @@ export function autoTypedSchema() {
445445
},
446446
methods: {
447447
instanceFn() {
448-
expectAssignable<Document<any, any, M0_0aAutoTypedSchemaType['schema']>>(this);
448+
expectType<HydratedDocument<M0_0aAutoTypedSchemaType['schema']>>(this);
449449
return 'Returned from DocumentInstanceFn' as const;
450450
}
451451
},

types/schemaoptions.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare module 'mongoose' {
1111
type TypeKeyBaseType = string;
1212

1313
type DefaultTypeKey = 'type';
14-
interface SchemaOptions<PathTypeKey extends TypeKeyBaseType = DefaultTypeKey, DocType = unknown, InstanceMethods = {}, QueryHelpers = {}, StaticMethods = {}> {
14+
interface SchemaOptions<PathTypeKey extends TypeKeyBaseType = DefaultTypeKey, DocType = unknown, InstanceMethods = {}, QueryHelpers = {}, StaticMethods = {}, virtuals = {}> {
1515
/**
1616
* By default, Mongoose's init() function creates all the indexes defined in your model's schema by
1717
* calling Model.createIndexes() after you successfully connect to MongoDB. If you want to disable
@@ -192,12 +192,12 @@ declare module 'mongoose' {
192192
/**
193193
* Model Statics methods.
194194
*/
195-
statics?: Record<any, <T extends Model<DocType>>(this: T, ...args: any) => unknown> | StaticMethods,
195+
statics?: Record<any, (this: Model<DocType>, ...args: any) => unknown> | StaticMethods,
196196

197197
/**
198198
* Document instance methods.
199199
*/
200-
methods?: Record<any, <T extends Document<any, any, DocType>>(this: T, ...args: any) => unknown> | InstanceMethods,
200+
methods?: Record<any, (this: HydratedDocument<DocType>, ...args: any) => unknown> | InstanceMethods,
201201

202202
/**
203203
* Query helper functions

0 commit comments

Comments
 (0)