Skip to content

Commit

Permalink
test(types): add test case for #14573
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed May 7, 2024
1 parent 1e652c6 commit c802909
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
DefaultSchemaOptions,
HydratedSingleSubdocument,
Schema,
Document,
HydratedDocument,
Expand Down Expand Up @@ -1442,3 +1444,53 @@ function gh14367() {
flags: [true]
};
}

function gh14573() {
interface Names {
_id: Types.ObjectId;
firstName: string;
}

// Document definition
interface User {
names: Names;
}

// Define property overrides for hydrated documents
type THydratedUserDocument = {
names?: HydratedSingleSubdocument<Names>;
};

type UserMethods = {
getName(): Names | undefined;
};

type UserModelType = Model<User, {}, UserMethods, {}, THydratedUserDocument>;

const userSchema = new Schema<
User,
UserModelType,
UserMethods,
{},
{},
{},
DefaultSchemaOptions,
User,
THydratedUserDocument
>(
{
names: new Schema<Names>({ firstName: String })
},
{
methods: {
getName() {
const str: string | undefined = this.names?.firstName;
return this.names?.toObject();
}
}
}
);
const UserModel = model<User, UserModelType>('User', userSchema);
const doc = new UserModel({ names: { _id: '0'.repeat(24), firstName: 'foo' } });
doc.names?.ownerDocument();
}

0 comments on commit c802909

Please sign in to comment.