Skip to content

Commit

Permalink
Merge pull request #14800 from Automattic/vkarpov15/gh-14793
Browse files Browse the repository at this point in the history
types: make HydratedSingleSubdocument and HydratedArraySubdocument merge types instead of using &
  • Loading branch information
vkarpov15 committed Aug 13, 2024
2 parents 9742d5a + a9ff3f1 commit c3bd03e
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,37 @@ declare module 'mongoose' {
>
>
>;
export type HydratedSingleSubdocument<DocType, TOverrides = {}> = Types.Subdocument<unknown, Record<string, never>, DocType> & Require_id<DocType> & TOverrides;
export type HydratedArraySubdocument<DocType, TOverrides = {}> = Types.ArraySubdocument<unknown, Record<string, never>, DocType> & Require_id<DocType> & TOverrides;
export type HydratedSingleSubdocument<
DocType,
TOverrides = {}
> = IfAny<
DocType,
any,
TOverrides extends Record<string, never> ?
Types.Subdocument<unknown, Record<string, never>, DocType> & Require_id<DocType> :
IfAny<
TOverrides,
Types.Subdocument<unknown, Record<string, never>, DocType> & Require_id<DocType>,
Types.Subdocument<unknown, Record<string, never>, DocType> & MergeType<
Require_id<DocType>,
TOverrides
>
>
>;
export type HydratedArraySubdocument<DocType, TOverrides = {}> = IfAny<
DocType,
any,
TOverrides extends Record<string, never> ?
Types.ArraySubdocument<unknown, Record<string, never>, DocType> & Require_id<DocType> :
IfAny<
TOverrides,
Types.ArraySubdocument<unknown, Record<string, never>, DocType> & Require_id<DocType>,
Types.ArraySubdocument<unknown, Record<string, never>, DocType> & MergeType<
Require_id<DocType>,
TOverrides
>
>
>;

export type HydratedDocumentFromSchema<TSchema extends Schema> = HydratedDocument<
InferSchemaType<TSchema>,
Expand Down

0 comments on commit c3bd03e

Please sign in to comment.