Skip to content

Commit 8401b47

Browse files
committed
Merge branch 'master' into 8.11
2 parents 48f9574 + 987f1ad commit 8401b47

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

types/index.d.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -714,47 +714,53 @@ declare module 'mongoose' {
714714
[K in keyof T]: FlattenProperty<T[K]>;
715715
};
716716

717-
export type BufferToBinaryProperty<T> = T extends Buffer
718-
? mongodb.Binary
719-
: T extends Types.DocumentArray<infer ItemType>
720-
? Types.DocumentArray<BufferToBinary<ItemType>>
721-
: T extends Types.Subdocument<unknown, unknown, infer SubdocType>
722-
? HydratedSingleSubdocument<BufferToBinary<SubdocType>>
723-
: BufferToBinary<T>;
717+
export type BufferToBinaryProperty<T> = unknown extends Buffer
718+
? T
719+
: T extends Buffer
720+
? mongodb.Binary
721+
: T extends Types.DocumentArray<infer ItemType>
722+
? Types.DocumentArray<BufferToBinary<ItemType>>
723+
: T extends Types.Subdocument<unknown, unknown, infer SubdocType>
724+
? HydratedSingleSubdocument<BufferToBinary<SubdocType>>
725+
: BufferToBinary<T>;
724726

725727
/**
726728
* Converts any Buffer properties into mongodb.Binary instances, which is what `lean()` returns
727729
*/
728-
export type BufferToBinary<T> = T extends Buffer
729-
? mongodb.Binary
730-
: T extends Document
731-
? T
732-
: T extends TreatAsPrimitives
733-
? T
734-
: T extends Record<string, any>
735-
? {
736-
[K in keyof T]: BufferToBinaryProperty<T[K]>
737-
}
738-
: T;
730+
export type BufferToBinary<T> = unknown extends Buffer
731+
? T
732+
: T extends Buffer
733+
? mongodb.Binary
734+
: T extends Document
735+
? T
736+
: T extends TreatAsPrimitives
737+
? T
738+
: T extends Record<string, any>
739+
? {
740+
[K in keyof T]: BufferToBinaryProperty<T[K]>
741+
}
742+
: T;
739743

740744
/**
741-
* Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization
742-
*/
743-
export type BufferToJSON<T> = T extends Buffer
744-
? { type: 'buffer', data: number[] }
745-
: T extends Document
746-
? T
747-
: T extends TreatAsPrimitives
745+
* Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization
746+
*/
747+
export type BufferToJSON<T> = unknown extends Buffer
748+
? T
749+
: T extends Buffer
750+
? { type: 'buffer', data: number[] }
751+
: T extends Document
748752
? T
749-
: T extends Record<string, any> ? {
750-
[K in keyof T]: T[K] extends Buffer
751-
? { type: 'buffer', data: number[] }
752-
: T[K] extends Types.DocumentArray<infer ItemType>
753-
? Types.DocumentArray<BufferToBinary<ItemType>>
754-
: T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
755-
? HydratedSingleSubdocument<SubdocType>
756-
: BufferToBinary<T[K]>;
757-
} : T;
753+
: T extends TreatAsPrimitives
754+
? T
755+
: T extends Record<string, any> ? {
756+
[K in keyof T]: T[K] extends Buffer
757+
? { type: 'buffer', data: number[] }
758+
: T[K] extends Types.DocumentArray<infer ItemType>
759+
? Types.DocumentArray<BufferToBinary<ItemType>>
760+
: T[K] extends Types.Subdocument<unknown, unknown, infer SubdocType>
761+
? HydratedSingleSubdocument<SubdocType>
762+
: BufferToBinary<T[K]>;
763+
} : T;
758764

759765
/**
760766
* Converts any ObjectId properties into strings for JSON serialization

types/inferschematype.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,17 @@ type IsSchemaTypeFromBuiltinClass<T> = T extends (typeof String)
235235
? true
236236
: T extends Types.Decimal128
237237
? true
238-
: T extends Buffer
238+
: T extends NativeDate
239239
? true
240-
: T extends NativeDate
240+
: T extends (typeof Schema.Types.Mixed)
241241
? true
242-
: T extends (typeof Schema.Types.Mixed)
242+
: IfEquals<T, Schema.Types.ObjectId, true, false> extends true
243243
? true
244-
: IfEquals<T, Schema.Types.ObjectId, true, false>;
244+
: unknown extends Buffer
245+
? false
246+
: T extends Buffer
247+
? true
248+
: false;
245249

246250
/**
247251
* @summary Resolve path type by returning the corresponding type.

0 commit comments

Comments
 (0)