From d092fdcf06cf3063e2d35530676c00f2af4edbfb Mon Sep 17 00:00:00 2001 From: mohammad0-0ahmad Date: Mon, 4 Jul 2022 00:39:14 +0200 Subject: [PATCH] Fix one case of the reported issues. --- types/inferschematype.d.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index ce94e6221c0..0b2c6eb792b 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -1,4 +1,17 @@ -import { Schema, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType, Types, NumberSchemaDefinition, StringSchemaDefinition, BooleanSchemaDefinition, DateSchemaDefinition } from 'mongoose'; +import { + Schema, + InferSchemaType, + SchemaType, + SchemaTypeOptions, + TypeKeyBaseType, + Types, + NumberSchemaDefinition, + StringSchemaDefinition, + BooleanSchemaDefinition, + DateSchemaDefinition, + ObtainDocumentType, + DefaultTypeKey +} from 'mongoose'; declare module 'mongoose' { /** @@ -138,7 +151,8 @@ type ObtainDocumentPathType = Pa ? InferSchemaType : ResolvePathType< PathValueType extends PathWithTypePropertyBaseType ? PathValueType[TypeKey] : PathValueType, - PathValueType extends PathWithTypePropertyBaseType ? Omit : {} + PathValueType extends PathWithTypePropertyBaseType ? Omit : {}, + TypeKey >; /** @@ -153,7 +167,7 @@ type PathEnumOrString['enum']> = T extends ( * @param {Options} Options Document definition path options except path type. * @returns Number, "Number" or "number" will be resolved to string type. */ -type ResolvePathType = {}> = +type ResolvePathType = {}, TypeKey extends TypeKeyBaseType = DefaultTypeKey> = PathValueType extends Schema ? InferSchemaType : PathValueType extends (infer Item)[] ? IfEquals>[] : PathValueType extends StringSchemaDefinition ? PathEnumOrString : @@ -169,5 +183,5 @@ type ResolvePathType extends true ? any: IfEquals extends true ? any: PathValueType extends typeof SchemaType ? PathValueType['prototype'] : - PathValueType extends {} ? PathValueType : + PathValueType extends Record ? ObtainDocumentType : unknown;