Skip to content

Commit

Permalink
Merge pull request #13787 from Automattic/vkarpov15/gh-13780
Browse files Browse the repository at this point in the history
types(schematypes): add missing BigInt SchemaType
  • Loading branch information
vkarpov15 authored Aug 29, 2023
2 parents 90fc4d2 + a9db5ea commit 84e79b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,3 +1177,9 @@ function gh13702() {
const schema = new Schema({ name: String });
expectType<[IndexDefinition, IndexOptions][]>(schema.indexes());
}

function gh13780() {
const schema = new Schema({ num: Schema.Types.BigInt });
type InferredType = InferSchemaType<typeof schema>;
expectType<bigint | undefined>(null as unknown as InferredType['num']);
}
24 changes: 13 additions & 11 deletions types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor ? 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, 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<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;
8 changes: 8 additions & 0 deletions types/schematypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ declare module 'mongoose' {
enum(vals: string[] | number[]): this;
}

class BigInt extends SchemaType {
/** This schema type's name, to defend against minifiers that mangle function names. */
static schemaName: 'BigInt';

/** Default options for this SchemaType */
defaultOptions: Record<string, any>;
}

class Boolean extends SchemaType {
/** This schema type's name, to defend against minifiers that mangle function names. */
static schemaName: 'Boolean';
Expand Down

0 comments on commit 84e79b9

Please sign in to comment.