Skip to content

Commit

Permalink
Merge pull request #14989 from OguzBey/tojson-type-improve
Browse files Browse the repository at this point in the history
types: added toJSON:flattenObjectIds effect
  • Loading branch information
vkarpov15 authored Oct 29, 2024
2 parents 38ee9bf + f1607b0 commit 6d1eda7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions types/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,17 @@ declare module 'mongoose' {
set(value: string | Record<string, any>): this;

/** The return value of this method is used in calls to JSON.stringify(doc). */
toJSON(options?: ToObjectOptions & { flattenMaps?: true }): FlattenMaps<Require_id<DocType>>;
toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Require_id<DocType>>;
toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Require_id<DocType>>;
toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Require_id<DocType>>>;
toJSON(options: ToObjectOptions & { flattenMaps: false }): Require_id<DocType>;
toJSON<T = Require_id<DocType>>(options?: ToObjectOptions & { flattenMaps?: true }): FlattenMaps<T>;
toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Require_id<DocType>>;

toJSON<T = Require_id<DocType>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>;
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false }): T;
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<T>;

/** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
toObject(options?: ToObjectOptions): Require_id<DocType>;
Expand Down

0 comments on commit 6d1eda7

Please sign in to comment.