Skip to content

Commit

Permalink
Merge pull request #14160 from Automattic/vkarpov15/gh-14147
Browse files Browse the repository at this point in the history
types: handle using BigInt global class in schema definitions
  • Loading branch information
vkarpov15 committed Dec 7, 2023
2 parents e3a35c2 + fc635bf commit 2c8b6ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
11 changes: 11 additions & 0 deletions test/types/schema.test.ts
Expand Up @@ -1368,3 +1368,14 @@ function gh13424() {
const doc = new TestModel({});
expectType<Types.ObjectId | undefined>(doc.subDocArray[0]._id);
}

function gh14147() {
const affiliateSchema = new Schema({
balance: { type: BigInt, default: BigInt(0) }
});

const AffiliateModel = model('Affiliate', affiliateSchema);

const doc = new AffiliateModel();
expectType<bigint>(doc.balance);
}
25 changes: 13 additions & 12 deletions types/inferschematype.d.ts
Expand Up @@ -262,15 +262,16 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt ? bigint :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
PathValueType extends typeof Schema.Types.Mixed ? any:
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
IfEquals<PathValueType, {}> extends true ? any:
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
unknown;
IfEquals<PathValueType, BigInt> extends true ? bigint :
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
PathValueType extends typeof Schema.Types.Mixed ? any:
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
IfEquals<PathValueType, {}> extends true ? any:
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
unknown;

0 comments on commit 2c8b6ab

Please sign in to comment.