@@ -23,9 +23,7 @@ declare module 'mongoose' {
2323 * // result
2424 * type UserType = {userName?: string}
2525 */
26- type InferSchemaType < SchemaType > = SchemaType extends Schema < infer EnforcedDocType >
27- ? IsItRecordAndNotAny < EnforcedDocType > extends true ? EnforcedDocType : ObtainSchemaGeneric < SchemaType , 'DocType' >
28- : unknown ;
26+ type InferSchemaType < SchemaType > = ObtainSchemaGeneric < SchemaType , 'DocType' > ;
2927
3028 /**
3129 * @summary Obtains schema Generic type by using generic alias.
@@ -83,7 +81,7 @@ type PathWithTypePropertyBaseType<TypeKey extends TypeKeyBaseType> = { [k in Typ
8381 * @returns required paths keys of document definition.
8482 */
8583type RequiredPathKeys < T > = {
86- [ K in keyof T ] : T [ K ] extends RequiredPathBaseType ? K : never ;
84+ [ K in keyof T ] : T [ K ] extends RequiredPathBaseType ? IfEquals < T [ K ] , any , never , K > : never ;
8785} [ keyof T ] ;
8886
8987/**
@@ -139,16 +137,17 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
139137 * @returns Number, "Number" or "number" will be resolved to string type.
140138 */
141139type ResolvePathType < PathValueType , Options extends SchemaTypeOptions < PathValueType > = { } > =
142- PathValueType extends ( infer Item ) [ ] ? IfEquals < Item , never , Schema . Types . Mixed , ResolvePathType < Item > > [ ] :
143- PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema . Types . String ? PathEnumOrString < Options [ 'enum' ] > :
144- PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema . Types . Number ? number :
145- PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema . Types . Date ? Date :
146- PathValueType extends BufferConstructor | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
147- PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema . Types . Boolean ? boolean :
148- PathValueType extends 'objectId' | 'ObjectId' | typeof Schema . Types . ObjectId ? Schema . Types . ObjectId :
149- PathValueType extends ObjectConstructor | typeof Schema . Types . Mixed ? Schema . Types . Mixed :
150- PathValueType extends MapConstructor ? Map < string , ResolvePathType < Options [ 'of' ] > > :
151- PathValueType extends ArrayConstructor ? Schema . Types . Mixed [ ] :
152- keyof PathValueType extends keyof { } ? Schema . Types . Mixed :
140+ PathValueType extends ( infer Item ) [ ] ? IfEquals < Item , never , any , ResolvePathType < Item > > [ ] :
141+ PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema . Types . String ? PathEnumOrString < Options [ 'enum' ] > :
142+ PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema . Types . Number ? number :
143+ PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema . Types . Date ? Date :
144+ PathValueType extends BufferConstructor | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
145+ PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema . Types . Boolean ? boolean :
146+ PathValueType extends 'objectId' | 'ObjectId' | typeof Schema . Types . ObjectId ? Schema . Types . ObjectId :
147+ PathValueType extends MapConstructor ? Map < string , ResolvePathType < Options [ 'of' ] > > :
148+ PathValueType extends ArrayConstructor ? any [ ] :
149+ PathValueType extends typeof Schema . Types . Mixed ? any :
150+ IfEquals < PathValueType , ObjectConstructor > extends true ? any :
151+ IfEquals < PathValueType , { } > extends true ? any :
153152 PathValueType extends typeof SchemaType ? PathValueType [ 'prototype' ] :
154- unknown ;
153+ unknown ;
0 commit comments