Skip to content

Commit

Permalink
Refactor statics & methods props in SchemaOptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Mar 31, 2022
1 parent 2332068 commit c6bd5c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/types/document.test.ts
Expand Up @@ -183,6 +183,6 @@ function m0_0aDocument() {
/* Document-Methods-tests */
/* -------------------------------------------------------------------------- */

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

}
4 changes: 2 additions & 2 deletions test/types/schema.test.ts
@@ -1,4 +1,4 @@
import { Schema, Document, SchemaDefinition, Model, Types, InferSchemaType, SchemaType, Query } from 'mongoose';
import { Schema, Document, SchemaDefinition, Model, Types, InferSchemaType, SchemaType, Query, HydratedDocument } from 'mongoose';
import { expectType, expectError, expectAssignable } from 'tsd';

enum Genre {
Expand Down Expand Up @@ -445,7 +445,7 @@ export function autoTypedSchema() {
},
methods: {
instanceFn() {
expectAssignable<Document<any, any, M0_0aAutoTypedSchemaType['schema']>>(this);
expectType<HydratedDocument<M0_0aAutoTypedSchemaType['schema']>>(this);
return 'Returned from DocumentInstanceFn' as const;
}
},
Expand Down
6 changes: 3 additions & 3 deletions types/schemaoptions.d.ts
Expand Up @@ -11,7 +11,7 @@ declare module 'mongoose' {
type TypeKeyBaseType = string;

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

/**
* Document instance methods.
*/
methods?: Record<any, <T extends Document<any, any, DocType>>(this: T, ...args: any) => unknown> | InstanceMethods,
methods?: Record<any, (this: HydratedDocument<DocType>, ...args: any) => unknown> | InstanceMethods,

/**
* Query helper functions
Expand Down

0 comments on commit c6bd5c3

Please sign in to comment.