Skip to content

Commit 00ca5c8

Browse files
authored
Merge pull request Automattic#15274 from Automattic/vkarpov15/add-double
types: add mongoose.Types.Double
2 parents 3af7b50 + 6be3df0 commit 00ca5c8

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

lib/types/double.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Double type constructor
3+
*
4+
* #### Example:
5+
*
6+
* const pi = new mongoose.Types.Double(3.1415);
7+
*
8+
* @constructor Double
9+
*/
10+
11+
'use strict';
12+
13+
module.exports = require('bson').Double;

lib/types/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports.Document = // @deprecate
1212
exports.Embedded = require('./arraySubdocument');
1313

1414
exports.DocumentArray = require('./documentArray');
15+
exports.Double = require('./double');
1516
exports.Decimal128 = require('./decimal128');
1617
exports.ObjectId = require('./objectid');
1718

test/types/schema.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,3 +1738,11 @@ function gh15244() {
17381738
const schema = new Schema({});
17391739
schema.discriminator('Name', new Schema({}), { value: 'value' });
17401740
}
1741+
1742+
async function schemaDouble() {
1743+
const schema = new Schema({ balance: 'Double' });
1744+
const TestModel = model('Test', schema);
1745+
1746+
const doc = await TestModel.findOne().orFail();
1747+
expectType<Types.Double | null | undefined>(doc.balance);
1748+
}

types/inferschematype.d.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
312312
IfEquals<PathValueType, BigInt> extends true ? bigint :
313313
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
314314
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
315-
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
316-
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
317-
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
318-
PathValueType extends ArrayConstructor ? any[] :
319-
PathValueType extends typeof Schema.Types.Mixed ? any:
320-
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
321-
IfEquals<PathValueType, {}> extends true ? any:
322-
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
323-
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
324-
unknown,
315+
PathValueType extends 'double' | 'Double' | typeof Schema.Types.Double ? Types.Double :
316+
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
317+
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
318+
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
319+
PathValueType extends ArrayConstructor ? any[] :
320+
PathValueType extends typeof Schema.Types.Mixed ? any:
321+
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
322+
IfEquals<PathValueType, {}> extends true ? any:
323+
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
324+
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
325+
unknown,
325326
TypeHint>;

types/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,7 @@ declare module 'mongoose' {
104104
}
105105

106106
class UUID extends bson.UUID {}
107+
108+
class Double extends bson.Double {}
107109
}
108110
}

0 commit comments

Comments
 (0)