Skip to content

Commit 52fdd0f

Browse files
authored
Merge pull request #15704 from Automattic/vkarpov15/gh-15699
types: make inferRawDocType correctly infer empty array type `[]` as `any[]`
2 parents 3df7bbf + 64de4b2 commit 52fdd0f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

test/types/inferrawdoctype.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,10 @@ function HandlesAny() {
127127
type ActualNested = InferRawDocType<Record<string, any>>;
128128
expectType<{ [x: string]: any }>({} as ActualNested);
129129
}
130+
131+
function gh15699() {
132+
const schema = { unTypedArray: [] } as const;
133+
134+
type TSchema = InferRawDocType<typeof schema>;
135+
expectType<any[] | null | undefined>({} as unknown as TSchema['unTypedArray']);
136+
}

types/inferrawdoctype.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare module 'mongoose' {
6060
[PathValueType] extends [neverOrAny] ? PathValueType
6161
: PathValueType extends Schema ? InferSchemaType<PathValueType>
6262
: PathValueType extends ReadonlyArray<infer Item> ?
63-
Item extends never ? any[]
63+
[Item] extends [never] ? any[]
6464
: Item extends Schema ?
6565
// If Item is a schema, infer its type.
6666
Array<InferSchemaType<Item>>

0 commit comments

Comments
 (0)