diff --git a/lib/types/double.js b/lib/types/double.js new file mode 100644 index 00000000000..6117173570b --- /dev/null +++ b/lib/types/double.js @@ -0,0 +1,13 @@ +/** + * Double type constructor + * + * #### Example: + * + * const pi = new mongoose.Types.Double(3.1415); + * + * @constructor Double + */ + +'use strict'; + +module.exports = require('bson').Double; diff --git a/lib/types/index.js b/lib/types/index.js index d234f6bb62a..8252aabfb21 100644 --- a/lib/types/index.js +++ b/lib/types/index.js @@ -12,6 +12,7 @@ exports.Document = // @deprecate exports.Embedded = require('./arraySubdocument'); exports.DocumentArray = require('./documentArray'); +exports.Double = require('./double'); exports.Decimal128 = require('./decimal128'); exports.ObjectId = require('./objectid'); diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index b4035ceb651..9d1cb073f51 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -1738,3 +1738,11 @@ function gh15244() { const schema = new Schema({}); schema.discriminator('Name', new Schema({}), { value: 'value' }); } + +async function schemaDouble() { + const schema = new Schema({ balance: 'Double' }); + const TestModel = model('Test', schema); + + const doc = await TestModel.findOne().orFail(); + expectType(doc.balance); +} diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index 061cfb48adc..dac99d09d6c 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -312,14 +312,15 @@ type ResolvePathType extends true ? bigint : PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint : PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer : - IfEquals extends true ? Buffer : - PathValueType extends MapConstructor | 'Map' ? Map> : - IfEquals extends true ? Map> : - PathValueType extends ArrayConstructor ? any[] : - PathValueType extends typeof Schema.Types.Mixed ? any: - IfEquals extends true ? any: - IfEquals extends true ? any: - PathValueType extends typeof SchemaType ? PathValueType['prototype'] : - PathValueType extends Record ? ObtainDocumentType : - unknown, + PathValueType extends 'double' | 'Double' | typeof Schema.Types.Double ? Types.Double : + IfEquals extends true ? Buffer : + PathValueType extends MapConstructor | 'Map' ? Map> : + IfEquals extends true ? Map> : + PathValueType extends ArrayConstructor ? any[] : + PathValueType extends typeof Schema.Types.Mixed ? any: + IfEquals extends true ? any: + IfEquals extends true ? any: + PathValueType extends typeof SchemaType ? PathValueType['prototype'] : + PathValueType extends Record ? ObtainDocumentType : + unknown, TypeHint>; diff --git a/types/types.d.ts b/types/types.d.ts index 503a9b2c9f2..9c56959182e 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -104,5 +104,7 @@ declare module 'mongoose' { } class UUID extends bson.UUID {} + + class Double extends bson.Double {} } }