Skip to content

Commit 6be3df0

Browse files
committed
types: correct schema inference for doubles
1 parent a8d2f2f commit 6be3df0

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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>;

0 commit comments

Comments
 (0)