Skip to content

Commit a9db5ea

Browse files
committed
types: handle Schema.Types.BigInt in schema definition re: #13780
1 parent 7ec92a7 commit a9db5ea

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

test/types/schema.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,9 @@ function gh13702() {
11771177
const schema = new Schema({ name: String });
11781178
expectType<[IndexDefinition, IndexOptions][]>(schema.indexes());
11791179
}
1180+
1181+
function gh13780() {
1182+
const schema = new Schema({ num: Schema.Types.BigInt });
1183+
type InferredType = InferSchemaType<typeof schema>;
1184+
expectType<bigint | undefined>(null as unknown as InferredType['num']);
1185+
}

types/inferschematype.d.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,16 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
215215
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
216216
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
217217
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
218-
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
219-
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
220-
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
221-
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
222-
PathValueType extends ArrayConstructor ? any[] :
223-
PathValueType extends typeof Schema.Types.Mixed ? any:
224-
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
225-
IfEquals<PathValueType, {}> extends true ? any:
226-
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
227-
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
228-
unknown;
218+
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
219+
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt ? bigint :
220+
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
221+
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
222+
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
223+
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
224+
PathValueType extends ArrayConstructor ? any[] :
225+
PathValueType extends typeof Schema.Types.Mixed ? any:
226+
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
227+
IfEquals<PathValueType, {}> extends true ? any:
228+
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
229+
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
230+
unknown;

0 commit comments

Comments
 (0)