Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(documentarray): typed DocumentArray constructor parameter #13089

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/types/docArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, model, Document, Types } from 'mongoose';
import { Schema, model, Types, InferSchemaType } from 'mongoose';
import { expectError, expectType } from 'tsd';

async function gh10293() {
Expand All @@ -24,3 +24,13 @@ async function gh10293() {
return test.arrayOfArray; // <-- error here if the issue persisted
};
}

function gh13087() {
interface Book {
author: {
name: string;
};
}

expectError(new Types.DocumentArray<Book>([1, 2, 3]));
}
2 changes: 1 addition & 1 deletion types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ declare module 'mongoose' {

class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
/** DocumentArray constructor */
constructor(values: any[]);
constructor(values: (AnyKeys<T> & AnyObject)[]);

isMongooseDocumentArray: true;

Expand Down