Skip to content

InferSchemaType produces DocumentArray instead of a simple Array #13772

Open
@juona

Description

@juona

Prerequisites

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

Mongoose version

7.4.4

Node.js version

16.19.1

MongoDB server version

5

Typescript version (if applicable)

4.8.3

Description

The InferSchemaType utility converts subdocument arrays into DocumentArrays. My understanding is that this utility should produce a plain type that has nothing to do with Mongoose, so it should infer simple arrays instead of DocumentArrays. Is my expectation incorrect?

Possibly related: #12030 .

Steps to Reproduce

const mySchema = new Schema({
    nodes: {
        type: [
            new Schema({
                foo: String
            })
        ],
        required: true
    }
});

type IMySchema = InferSchemaType<typeof mySchema>;

Type IMySchema is:

type IMySchema = {
    nodes: Types.DocumentArray<{
        foo?: string | undefined;
    }>;
}

Expected Behavior

I'd expect type IMySchema to be:

type IMySchema = {
    nodes: Array<{
        foo?: string | undefined;
    }>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions