Skip to content

Commit 57540aa

Browse files
committedSep 1, 2021
fix(index.d.ts): allow using type: [documentDefinition] when defining a doc array in a schema
Fix #10605
1 parent 1a1a2f2 commit 57540aa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎index.d.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1528,15 +1528,17 @@ declare module 'mongoose' {
15281528
U :
15291529
T extends ReadonlyArray<infer U> ? U : T;
15301530

1531+
type AnyArray<T> = T[] | ReadonlyArray<T>;
1532+
15311533
export class SchemaTypeOptions<T> {
15321534
type?:
15331535
T extends string | number | boolean | NativeDate | Function ? SchemaDefinitionWithBuiltInClass<T> :
15341536
T extends Schema<any, any> ? T :
1535-
T extends object[] ? (Schema<Unpacked<T>>[] | ReadonlyArray<Schema<Unpacked<T>>> | Schema<Document & Unpacked<T>>[] | ReadonlyArray<Schema<Document & Unpacked<T>>>) :
1536-
T extends string[] ? (SchemaDefinitionWithBuiltInClass<string>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<string>>) :
1537-
T extends number[] ? (SchemaDefinitionWithBuiltInClass<number>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<number>>) :
1538-
T extends boolean[] ? (SchemaDefinitionWithBuiltInClass<boolean>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<boolean>>) :
1539-
T extends Function[] ? (SchemaDefinitionWithBuiltInClass<Function>[] | ReadonlyArray<SchemaDefinitionWithBuiltInClass<Function>>) :
1537+
T extends object[] ? (AnyArray<Schema<Unpacked<T>>> | AnyArray<Schema<Document & Unpacked<T>>> | AnyArray<SchemaDefinition<Unpacked<T>>>) :
1538+
T extends string[] ? AnyArray<SchemaDefinitionWithBuiltInClass<string>> :
1539+
T extends number[] ? AnyArray<SchemaDefinitionWithBuiltInClass<number>> :
1540+
T extends boolean[] ? AnyArray<SchemaDefinitionWithBuiltInClass<boolean>> :
1541+
T extends Function[] ? AnyArray<SchemaDefinitionWithBuiltInClass<Function>> :
15401542
T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T>;
15411543

15421544
/** Defines a virtual with the given name that gets/sets this path. */

0 commit comments

Comments
 (0)
Please sign in to comment.