Skip to content

Model.hydrate() TS error: Argument of type 'string' is not assignable to parameter of type 'AnyObject' #15437

Closed
@fraction01

Description

@fraction01

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

Node.js version

20

MongoDB server version

7.0

Typescript version (if applicable)

5.7.3

Description

Model.hydrate() projection argument only accept AnyObject

hydrate(obj: any, projection?: AnyObject, options?: HydrateOptions): THydratedDocumentType;

mongoose/types/index.d.ts

Lines 134 to 136 in 0c5f56f

export interface AnyObject {
[k: string]: any
}

Steps to Reproduce

const mongooseCandy = Candy.hydrate({ _id: '54108337212ffb6d459f854c', type: 'jelly bean' }, 'type');

Or

const mongooseCandy = Candy.hydrate({ _id: '54108337212ffb6d459f854c', type: 'jelly bean' }, ['type']);

Expected Behavior

It should also accept string and string[] as stated in the doc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypes or Types-test related issue / Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions