diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index 8af390a42bf..5cc9dfa138f 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -1,4 +1,4 @@ -import { Schema, Types, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType } from 'mongoose'; +import { Schema, Types, InferSchemaType, ObtainDocumentType, SchemaDefinitionProperty, SchemaType, SchemaTypeOptions, TypeKeyBaseType } from 'mongoose'; declare module 'mongoose' { /** @@ -149,18 +149,19 @@ type PathEnumOrString['enum']> = T extends ( * @returns Number, "Number" or "number" will be resolved to string type. */ type ResolvePathType = {}> = - PathValueType extends (infer Item)[] ? ObtainDocumentPathType[] : - PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema.Types.String ? PathEnumOrString : - PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema.Types.Number ? number : - PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema.Types.Date ? Date : - PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : - PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean ? boolean : - PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Types.ObjectId : - PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 : - PathValueType extends MapConstructor ? Map> : - PathValueType extends ArrayConstructor ? any[] : - PathValueType extends typeof Schema.Types.Mixed ? any : - IfEquals extends true ? any : - IfEquals extends true ? any : - PathValueType extends typeof SchemaType ? PathValueType['prototype'] : - unknown; + PathValueType extends (infer Item)[] ? IfEquals>[] : + PathValueType extends { [K: string]: SchemaDefinitionProperty } ? ObtainDocumentType : + PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema.Types.String ? PathEnumOrString : + PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema.Types.Number ? number : + PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema.Types.Date ? Date : + PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : + PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean ? boolean : + PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Types.ObjectId : + PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 : + PathValueType extends MapConstructor ? Map> : + PathValueType extends ArrayConstructor ? any[] : + PathValueType extends typeof Schema.Types.Mixed ? any : + IfEquals extends true ? any : + IfEquals extends true ? any : + PathValueType extends typeof SchemaType ? PathValueType['prototype'] : + unknown;