diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 86e4d2668a4..2ab4698e4bc 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -412,6 +412,7 @@ export function autoTypedSchema() { array5: any[]; array6: string[]; array7?: string[]; + array8?: string[]; decimal1?: Types.Decimal128; decimal2?: Types.Decimal128; decimal3?: Types.Decimal128; @@ -458,6 +459,7 @@ export function autoTypedSchema() { array5: [], array6: { type: [String] }, array7: { type: [String], default: undefined }, + array8: { type: [String], default: () => undefined }, decimal1: Schema.Types.Decimal128, decimal2: 'Decimal128', decimal3: 'decimal128' diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index a0406388f00..27090b89eb4 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -60,6 +60,12 @@ declare module 'mongoose' { : unknown; } +type IsPathDefaultUndefined = PathType extends { default: undefined } ? + true : + PathType extends { default: (...args: any[]) => undefined } ? + true : + false; + /** * @summary Checks if a document path is required or optional. * @param {P} P Document path. @@ -69,7 +75,7 @@ type IsPathRequired = P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[] ? true : P extends (Record) - ? P extends { default: undefined } + ? IsPathDefaultUndefined

extends true ? false : true : P extends (Record)