@@ -23,8 +23,8 @@ declare module 'mongoose' {
2323 * // result
2424 * type UserType = {userName?: string}
2525 */
26- type InferSchemaType < SchemaType > = SchemaType extends Schema < infer DocType >
27- ? IsItRecordAndNotAny < DocType > extends true ? DocType : ObtainSchemaGeneric < SchemaType , 'DocType' >
26+ type InferSchemaType < SchemaType > = SchemaType extends Schema < infer EnforcedDocType >
27+ ? IsItRecordAndNotAny < EnforcedDocType > extends true ? EnforcedDocType : ObtainSchemaGeneric < SchemaType , 'DocType' >
2828 : unknown ;
2929
3030 /**
@@ -51,7 +51,9 @@ declare module 'mongoose' {
5151 * @param {T } T A generic type to be checked.
5252 * @returns true if {@link T} is Record OR false if {@link T} is of any type.
5353 */
54- type IsItRecordAndNotAny < T > = T extends any [ ] ? false : T extends Record < any , any > ? true : false ;
54+ type IsItRecordAndNotAny < T > = IsTAny < T > extends true ? false : T extends Record < any , any > ? true : false ;
55+
56+ type IsTAny < T > = keyof any extends keyof T ? ( unknown extends T ? true : false ) : false ;
5557
5658/**
5759 * @summary Required path base type.
@@ -128,15 +130,17 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
128130 * @returns Number, "Number" or "number" will be resolved to string type.
129131 */
130132type ResolvePathType < PathValueType , Options extends SchemaTypeOptions < PathValueType > = { } > =
131- PathValueType extends ( infer Item ) [ ] ? ResolvePathType < Item > [ ] :
132- PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema . Types . String ? PathEnumOrString < Options [ 'enum' ] > :
133- PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema . Types . Number ? number :
134- PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema . Types . Date ? Date :
135- PathValueType extends BufferConstructor | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
136- PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema . Types . Boolean ? boolean :
137- PathValueType extends 'objectId' | 'ObjectId' | typeof Schema . Types . ObjectId ? Schema . Types . ObjectId :
138- PathValueType extends ObjectConstructor | typeof Schema . Types . Mixed ? Schema . Types . Mixed :
139- keyof PathValueType extends never ? Schema . Types . Mixed :
140- PathValueType extends MapConstructor ? Map < string , ResolvePathType < Options [ 'of' ] > > :
141- PathValueType extends typeof SchemaType ? PathValueType [ 'prototype' ] :
142- unknown ;
133+ IsTAny < PathValueType > extends true ? Schema . Types . Mixed :
134+ PathValueType extends ( infer Item ) [ ] ? ResolvePathType < Item > [ ] :
135+ PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema . Types . String ? PathEnumOrString < Options [ 'enum' ] > :
136+ PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema . Types . Number ? number :
137+ PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema . Types . Date ? Date :
138+ PathValueType extends BufferConstructor | 'buffer' | 'Buffer' | typeof Schema . Types . Buffer ? Buffer :
139+ PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema . Types . Boolean ? boolean :
140+ PathValueType extends 'objectId' | 'ObjectId' | typeof Schema . Types . ObjectId ? Schema . Types . ObjectId :
141+ PathValueType extends ObjectConstructor | typeof Schema . Types . Mixed ? Schema . Types . Mixed :
142+ PathValueType extends MapConstructor ? Map < string , ResolvePathType < Options [ 'of' ] > > :
143+ PathValueType extends ArrayConstructor ? Schema . Types . Mixed [ ] :
144+ keyof PathValueType extends keyof { } ? Schema . Types . Mixed :
145+ PathValueType extends typeof SchemaType ? PathValueType [ 'prototype' ] :
146+ unknown ;
0 commit comments