diff --git a/package.json b/package.json index 47930c2e8dc..332937da548 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "@babel/preset-env": "7.20.2", "@typescript-eslint/eslint-plugin": "5.50.0", "@typescript-eslint/parser": "5.50.0", - "acquit": "1.2.1", - "acquit-ignore": "0.2.0", + "acquit": "1.3.0", + "acquit-ignore": "0.2.1", "acquit-require": "0.1.1", "assert-browserify": "2.0.0", "axios": "1.1.3", diff --git a/test/types/.eslintrc.yml b/test/types/.eslintrc.yml new file mode 100644 index 00000000000..7e081732529 --- /dev/null +++ b/test/types/.eslintrc.yml @@ -0,0 +1,2 @@ +rules: + "@typescript-eslint/no-empty-interface": off \ No newline at end of file diff --git a/test/types/lean.test.ts b/test/types/lean.test.ts index 6b4bfccb201..2a7088812a3 100644 --- a/test/types/lean.test.ts +++ b/test/types/lean.test.ts @@ -182,7 +182,7 @@ async function getBaseDocumentTypeFromModel(): Promise { type baseFromUserDocType = BaseDocumentType; - expectType({} as baseFromUserDocType); + expectType>({} as baseFromUserDocType); const a: UserDocType = {} as any; diff --git a/test/types/subdocuments.test.ts b/test/types/subdocuments.test.ts index 58fe37162a6..5b690a44fcb 100644 --- a/test/types/subdocuments.test.ts +++ b/test/types/subdocuments.test.ts @@ -76,3 +76,35 @@ function gh10674() { async function gh10947(): Promise { await Test.findOneAndUpdate({}, { child1: { name: 'foo' } }); } + +function gh13040(): void { + interface Product {} + + interface User { + products: Product[]; + } + + // I want my `UserDocument` type to define `products` as a `DocumentArray`; I'll do this using overrides + + interface UserOverrides { + products: Types.DocumentArray; + } + + type UserModel = Model; + + // Here I determine the type of user documents; I could also manually define a `HydratedDocument` - makes no difference. + + type UserDocument = InstanceType; + + // Assume I have an instance of `UserDocument` + + let user!: UserDocument; + + // This is then fine: + + user.products[0].ownerDocument(); // ok + + user.products.forEach(product => { + product.ownerDocument(); + }); +} diff --git a/types/index.d.ts b/types/index.d.ts index 640355a15b8..ac24805858c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -129,12 +129,14 @@ declare module 'mongoose' { ? IfAny> : T & { _id: Types.ObjectId }; - export type HydratedDocument = DocType extends Document ? Require_id : (Document & Require_id & TVirtuals & TMethodsAndOverrides); + export type HydratedDocument = DocType extends Document ? + Require_id : + Document & MergeType, TVirtuals & TMethodsAndOverrides>; export type HydratedDocumentFromSchema = HydratedDocument< InferSchemaType, - ObtainSchemaGeneric, - ObtainSchemaGeneric + ObtainSchemaGeneric, + ObtainSchemaGeneric >; export interface TagSet {