Skip to content

Commit 2c8b6ab

Browse files
authored
Merge pull request #14160 from Automattic/vkarpov15/gh-14147
types: handle using BigInt global class in schema definitions
2 parents e3a35c2 + fc635bf commit 2c8b6ab

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

test/types/schema.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1368,3 +1368,14 @@ function gh13424() {
13681368
const doc = new TestModel({});
13691369
expectType<Types.ObjectId | undefined>(doc.subDocArray[0]._id);
13701370
}
1371+
1372+
function gh14147() {
1373+
const affiliateSchema = new Schema({
1374+
balance: { type: BigInt, default: BigInt(0) }
1375+
});
1376+
1377+
const AffiliateModel = model('Affiliate', affiliateSchema);
1378+
1379+
const doc = new AffiliateModel();
1380+
expectType<bigint>(doc.balance);
1381+
}

types/inferschematype.d.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,16 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
262262
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
263263
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
264264
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
265-
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt ? bigint :
266-
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
267-
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
268-
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
269-
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
270-
PathValueType extends ArrayConstructor ? any[] :
271-
PathValueType extends typeof Schema.Types.Mixed ? any:
272-
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
273-
IfEquals<PathValueType, {}> extends true ? any:
274-
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
275-
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
276-
unknown;
265+
IfEquals<PathValueType, BigInt> extends true ? bigint :
266+
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
267+
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
268+
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
269+
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
270+
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
271+
PathValueType extends ArrayConstructor ? any[] :
272+
PathValueType extends typeof Schema.Types.Mixed ? any:
273+
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
274+
IfEquals<PathValueType, {}> extends true ? any:
275+
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
276+
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
277+
unknown;

0 commit comments

Comments
 (0)