diff --git a/types/index.d.ts b/types/index.d.ts index e95c44048e..425ed49110 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -712,47 +712,53 @@ declare module 'mongoose' { [K in keyof T]: FlattenProperty; }; - export type BufferToBinaryProperty = T extends Buffer - ? mongodb.Binary - : T extends Types.DocumentArray - ? Types.DocumentArray> - : T extends Types.Subdocument - ? HydratedSingleSubdocument> - : BufferToBinary; + export type BufferToBinaryProperty = unknown extends Buffer + ? T + : T extends Buffer + ? mongodb.Binary + : T extends Types.DocumentArray + ? Types.DocumentArray> + : T extends Types.Subdocument + ? HydratedSingleSubdocument> + : BufferToBinary; /** * Converts any Buffer properties into mongodb.Binary instances, which is what `lean()` returns */ - export type BufferToBinary = T extends Buffer - ? mongodb.Binary - : T extends Document - ? T - : T extends TreatAsPrimitives - ? T - : T extends Record - ? { - [K in keyof T]: BufferToBinaryProperty - } - : T; + export type BufferToBinary = unknown extends Buffer + ? T + : T extends Buffer + ? mongodb.Binary + : T extends Document + ? T + : T extends TreatAsPrimitives + ? T + : T extends Record + ? { + [K in keyof T]: BufferToBinaryProperty + } + : T; /** - * Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization - */ - export type BufferToJSON = T extends Buffer - ? { type: 'buffer', data: number[] } - : T extends Document - ? T - : T extends TreatAsPrimitives + * Converts any Buffer properties into { type: 'buffer', data: [1, 2, 3] } format for JSON serialization + */ + export type BufferToJSON = unknown extends Buffer + ? T + : T extends Buffer + ? { type: 'buffer', data: number[] } + : T extends Document ? T - : T extends Record ? { - [K in keyof T]: T[K] extends Buffer - ? { type: 'buffer', data: number[] } - : T[K] extends Types.DocumentArray - ? Types.DocumentArray> - : T[K] extends Types.Subdocument - ? HydratedSingleSubdocument - : BufferToBinary; - } : T; + : T extends TreatAsPrimitives + ? T + : T extends Record ? { + [K in keyof T]: T[K] extends Buffer + ? { type: 'buffer', data: number[] } + : T[K] extends Types.DocumentArray + ? Types.DocumentArray> + : T[K] extends Types.Subdocument + ? HydratedSingleSubdocument + : BufferToBinary; + } : T; /** * Converts any ObjectId properties into strings for JSON serialization diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index 38f8da1ed6..061cfb48ad 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -235,13 +235,17 @@ type IsSchemaTypeFromBuiltinClass = T extends (typeof String) ? true : T extends Types.Decimal128 ? true - : T extends Buffer + : T extends NativeDate ? true - : T extends NativeDate + : T extends (typeof Schema.Types.Mixed) ? true - : T extends (typeof Schema.Types.Mixed) + : IfEquals extends true ? true - : IfEquals; + : unknown extends Buffer + ? false + : T extends Buffer + ? true + : false; /** * @summary Resolve path type by returning the corresponding type.