Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up all but 1 test
  • Loading branch information
vkarpov15 committed Sep 12, 2023
commit 585806182324fc79e2ea3b1b9c8e2806440b4e2c
3 changes: 3 additions & 0 deletions test/types/docArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ async function gh10293() {
});

const TestModel = model('gh10293TestModel', testSchema);
const doc = new TestModel();
expectType<string>(doc.name);
expectType<string[][]>(doc.arrayOfArray);

testSchema.methods.getArrayOfArray = function(this: InstanceType<typeof TestModel>): string[][] { // <-- function to return Array of Array
const test = this.toObject();
Expand Down
37 changes: 35 additions & 2 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,24 @@ function gh11828() {
}
};

new Schema<IUser>({
const schema = new Schema<IUser>({
name: { type: String, default: () => 'Hafez' },
age: { type: Number, default: () => 27 },
bornAt: { type: Date, default: () => new Date() },
isActive: {
type: Boolean,
default(): boolean {
default(this: HydratedDocument<IUser>): boolean {
return this.name === 'Hafez';
}
}
});

const UserModel = model<IUser>('User', schema);
const doc = new UserModel();
expectType<string>(doc.name);
expectType<number>(doc.age);
expectType<Date>(doc.bornAt);
expectType<boolean>(doc.isActive);
}

function gh11997() {
Expand Down Expand Up @@ -1154,6 +1161,32 @@ function gh13514() {
const str: string = doc.email;
}

function defaultFn() {
const schema = new Schema({
name: String,
email: {
type: String,
default() {
return this.name + '@test.com';
}
}
});
type X = ObtainSchemaGeneric<typeof schema, 'DocType'>;
const x: X = {
name: String,
email: {
type: String,
default() {
return this.name + '@test.com';
}
}
}
const Test = model('Test', schema);

const doc = new Test({ name: 'john' });
const str: string = doc.email;
}

function gh13633() {
const schema = new Schema({ name: String });

Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ declare module 'mongoose' {
TVirtuals = {},
TStaticMethods = {},
TSchemaOptions = DefaultSchemaOptions,
TSchemaDefinition extends SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> = any,
TSchemaDefinition = any,
DocType extends ApplySchemaOptions<
ObtainDocumentType<TSchemaDefinition, EnforcedDocType, ResolveSchemaOptions<TSchemaOptions>>,
ResolveSchemaOptions<TSchemaOptions>
Expand Down
2 changes: 1 addition & 1 deletion types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ declare module 'mongoose' {

type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined } ?
true :
PathType extends { default: (...args: any[]) => undefined } ?
PathType extends { default: (this: any, ...args: any[]) => undefined } ?
true :
false;

Expand Down