diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index cf85c5c0e5c..39a2167bfbc 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -362,9 +362,9 @@ export function autoTypedSchema() { boolean2?: boolean; boolean3?: boolean; boolean4?: boolean; - mixed1?: Schema.Types.Mixed; - mixed2?: Schema.Types.Mixed; - mixed3?: Schema.Types.Mixed; + mixed1?: any; + mixed2?: any; + mixed3?: any; objectId1?: Schema.Types.ObjectId; objectId2?: Schema.Types.ObjectId; objectId3?: Schema.Types.ObjectId; @@ -372,10 +372,10 @@ export function autoTypedSchema() { map1?: Map; map2?: Map; array1?: string[]; - array2?: Schema.Types.Mixed[]; - array3?: Schema.Types.Mixed[]; - array4?: Schema.Types.Mixed[]; - array5?: Schema.Types.Mixed[]; + array2?: any[]; + array3?: any[]; + array4?: any[]; + array5?: any[]; }; const TestSchema = new Schema({ diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index e24715a5254..5159eb08dcf 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -23,9 +23,7 @@ declare module 'mongoose' { * // result * type UserType = {userName?: string} */ - type InferSchemaType = SchemaType extends Schema - ? IsItRecordAndNotAny extends true ? EnforcedDocType : ObtainSchemaGeneric - : unknown; + type InferSchemaType = ObtainSchemaGeneric ; /** * @summary Obtains schema Generic type by using generic alias. @@ -83,7 +81,7 @@ type PathWithTypePropertyBaseType = { [k in Typ * @returns required paths keys of document definition. */ type RequiredPathKeys = { - [K in keyof T]: T[K] extends RequiredPathBaseType ? K : never; + [K in keyof T]: T[K] extends RequiredPathBaseType ? IfEquals : never; }[keyof T]; /** @@ -139,16 +137,17 @@ type PathEnumOrString['enum']> = T extends ( * @returns Number, "Number" or "number" will be resolved to string type. */ type ResolvePathType = {}> = - PathValueType extends (infer Item)[] ? IfEquals>[] : - 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 BufferConstructor | '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 ? Schema.Types.ObjectId : - PathValueType extends ObjectConstructor | typeof Schema.Types.Mixed ? Schema.Types.Mixed : - PathValueType extends MapConstructor ? Map> : - PathValueType extends ArrayConstructor ? Schema.Types.Mixed[] : - keyof PathValueType extends keyof {} ? Schema.Types.Mixed : + PathValueType extends (infer Item)[] ? IfEquals>[] : + 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 BufferConstructor | '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 ? Schema.Types.ObjectId : + 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; + unknown; \ No newline at end of file