Skip to content

Commit

Permalink
fix(types): use this for return type from $assertPopulated()
Browse files Browse the repository at this point in the history
Fix #12234
  • Loading branch information
vkarpov15 committed Aug 27, 2022
1 parent d79e117 commit 76201d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/types/populate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ async function gh11710() {
expectType<Child | null>(doc.child);
}

function gh11758() {
async function gh11758() {
interface NestedChild {
name: string
_id: Types.ObjectId
Expand All @@ -297,6 +297,8 @@ function gh11758() {
}).$assertPopulated<{ nestedChild: NestedChild }>('nestedChild');

expectType<string>(parent.nestedChild.name);

await parent.save();
}

async function gh11955() {
Expand Down
2 changes: 1 addition & 1 deletion types/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare module 'mongoose' {
__v?: any;

/** Assert that a given path or paths is populated. Throws an error if not populated. */
$assertPopulated<Paths = {}>(paths: string | string[]): Omit<DocType, keyof Paths> & Paths;
$assertPopulated<Paths = {}>(paths: string | string[]): Omit<this, keyof Paths> & Paths;

/* Get all subdocs (by bfs) */
$getAllSubdocs(): Document[];
Expand Down

0 comments on commit 76201d0

Please sign in to comment.