Skip to content

Unexpected error executing a lean query and passing the result of the query to a function that accepts a variable of that interface type. #15275

@nikzanda

Description

@nikzanda

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.10.2

Node.js version

20.10.0

MongoDB server version

6.0.2

Typescript version (if applicable)

5.7.2

Description

I have a model Post that references the model User. The User model includes an embedded field, addresses, which is overridden by the type UserDocumentOverrides using Types.DocumentArray<AddressInstance>. For some reason, this override causes a typing error when performing a lean query on the Post model and passing the query result to a function that expects a parameter of type IPost[].

Steps to Reproduce

Reproduction link here.

P.S. If I locally comment out line 21 of the user.ts file, the error disappears. However, for some reason, on StackBlitz, the error remains.

Expected Behavior

As a workaround, I can manually infer the type during the query .lean<IPost[]>(). However, I don't expect this type of error and having to manually specify the typing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions