Skip to content

Commit a9c515b

Browse files
committed
types: quick fix to handle empty objects
1 parent af7ae41 commit a9c515b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

test/types/schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export function autoTypedSchema() {
408408
array1: string[];
409409
array2: any[];
410410
array3: any[];
411-
// array4: any[];
411+
array4: any[];
412412
array5: any[];
413413
array6: string[];
414414
array7?: string[] | null;
@@ -455,7 +455,7 @@ export function autoTypedSchema() {
455455
array1: [String],
456456
array2: Array,
457457
array3: [Schema.Types.Mixed],
458-
// array4: [{}],
458+
array4: [{}],
459459
array5: [],
460460
array6: { type: [String] },
461461
array7: { type: [String], default: undefined },

types/inferschematype.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
225225
IsSchemaTypeFromBuiltinClass<Item> extends true ?
226226
ObtainDocumentPathType<Item, TypeKey>[] :
227227
IsItRecordAndNotAny<Item> extends true ?
228-
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
228+
Item extends Record<string, never> ?
229+
ObtainDocumentPathType<Item, TypeKey>[] :
230+
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
229231
ObtainDocumentPathType<Item, TypeKey>[]
230232
>:
231233
PathValueType extends ReadonlyArray<infer Item> ?
@@ -238,7 +240,9 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
238240
IsSchemaTypeFromBuiltinClass<Item> extends true ?
239241
ObtainDocumentPathType<Item, TypeKey>[] :
240242
IsItRecordAndNotAny<Item> extends true ?
241-
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
243+
Item extends Record<string, never> ?
244+
ObtainDocumentPathType<Item, TypeKey>[] :
245+
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
242246
ObtainDocumentPathType<Item, TypeKey>[]
243247
>:
244248
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :

0 commit comments

Comments
 (0)