Skip to content

InferRawDocType behaves differently in v8.19 (bug?) #15699

@Systerr

Description

@Systerr

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.19

Node.js version

24

MongoDB server version

8

Typescript version (if applicable)

5

Description

In version 8.19 behavior for untyped arrays in InferRawDocType was changed.

const schema = { unTypedArray: [] };

type TSchema = InferRawDocType<typeof schema>;

It now generates the following type:

type TSchema = {
    unTypedArray: never;
}

According to the documentation:
| Note: specifying an empty array is equivalent to Mixed
https://github.com/Automattic/mongoose/blob/master/docs/schematypes.md?plain=1#L502

For the Mixed type, everything works as expected:

const schema = { mixedArray: [Schema.Types.Mixed] };

type TSchema = InferRawDocType<typeof schema>;

This generates:

type TSchema = {
   mixedArray: any[];
}

In version 8.18, both an empty array and Schema.Types.Mixed correctly generated the type any[].

Steps to Reproduce

see above

Expected Behavior

All possible schema types ([], [Mixed]) should produce correct types

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions