diff --git a/test/types/inferrawdoctype.test.ts b/test/types/inferrawdoctype.test.ts index c67ae090fa..743bb85be7 100644 --- a/test/types/inferrawdoctype.test.ts +++ b/test/types/inferrawdoctype.test.ts @@ -1,6 +1,28 @@ -import { InferRawDocType, type InferSchemaType, type ResolveTimestamps, type Schema, type Types } from 'mongoose'; -import { expectType, expectError } from 'tsd'; +import { InferRawDocType, type InferPojoType, type ResolveTimestamps, type Schema, type Types } from 'mongoose'; +import { expectType } from 'tsd'; +function inferPojoType() { + 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 = InferPojoType< typeof schemaDefinition>; + expectType<{ email: string, password: string, dateOfBirth: Date }>({} as UserType); +} function gh14839() { const schemaDefinition = { email: { diff --git a/types/inferrawdoctype.d.ts b/types/inferrawdoctype.d.ts index 9e54ef3ea0..906e457158 100644 --- a/types/inferrawdoctype.d.ts +++ b/types/inferrawdoctype.d.ts @@ -12,18 +12,24 @@ declare module 'mongoose' { ? ObtainSchemaGeneric : FlattenMaps>>; - export type InferRawDocType< + export type InferPojoType< SchemaDefinition, TSchemaOptions extends Record = DefaultSchemaOptions, TTransformOptions = { bufferToBinary: false } - > = Require_id = ApplySchemaOptions<{ [ K in keyof (RequiredPaths & OptionalPaths) ]: IsPathRequired extends true ? ObtainRawDocumentPathType : ObtainRawDocumentPathType | null; - }, TSchemaOptions>>; + }, TSchemaOptions>; + + export type InferRawDocType< + SchemaDefinition, + TSchemaOptions extends Record = DefaultSchemaOptions, + TTransformOptions = { bufferToBinary: false } + > = Require_id>; /** * @summary Allows users to optionally choose their own type for a schema field for stronger typing.