diff --git a/test/types/inferrawdoctype.test.ts b/test/types/inferrawdoctype.test.ts new file mode 100644 index 0000000000..7d162b0397 --- /dev/null +++ b/test/types/inferrawdoctype.test.ts @@ -0,0 +1,25 @@ +import { InferRawDocType } from 'mongoose'; +import { expectType, expectError } from 'tsd'; + +function gh14839() { + const schemaDefinition = { + email: { + type: String, + trim: true, + required: true, + unique: true, + lowercase: true + }, + password: { + type: String, + required: true + }, + dateOfBirth: { + type: Date, + required: true + } + }; + + type UserType = InferRawDocType< typeof schemaDefinition>; + expectType<{ email: string, password: string, dateOfBirth: Date }>({} as UserType); +} diff --git a/types/inferrawdoctype.d.ts b/types/inferrawdoctype.d.ts index 5ef52e1325..605571057a 100644 --- a/types/inferrawdoctype.d.ts +++ b/types/inferrawdoctype.d.ts @@ -91,8 +91,8 @@ declare module 'mongoose' { IfEquals extends true ? PathEnumOrString : PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray ? Options['enum'][number] : number : IfEquals extends true ? number : - PathValueType extends DateSchemaDefinition ? Date : - IfEquals extends true ? Date : + PathValueType extends DateSchemaDefinition ? NativeDate : + IfEquals extends true ? NativeDate : PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : PathValueType extends BooleanSchemaDefinition ? boolean : IfEquals extends true ? boolean : diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index dbcb3ad851..07ee5087b3 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -281,8 +281,8 @@ type ResolvePathType extends true ? PathEnumOrString : PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray ? Options['enum'][number] : number : IfEquals extends true ? number : - PathValueType extends DateSchemaDefinition ? Date : - IfEquals extends true ? Date : + PathValueType extends DateSchemaDefinition ? NativeDate : + IfEquals extends true ? NativeDate : PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : PathValueType extends BooleanSchemaDefinition ? boolean : IfEquals extends true ? boolean :