Skip to content

Commit 5c03f80

Browse files
committed
fix linting problems and add this type to default function
1 parent cfbccec commit 5c03f80

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

test/types/schema.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1223,5 +1223,10 @@ async function gh13797() {
12231223
interface IUser {
12241224
name: string;
12251225
}
1226-
const schema2 = new Schema<IUser>({ name: { type: String, required: function () { expectType<IUser>(this); return true } } });
1226+
new Schema<IUser>({ name: { type: String, required: function() {
1227+
expectType<IUser>(this); return true;
1228+
} } });
1229+
new Schema<IUser>({ name: { type: String, default: function() {
1230+
expectType<IUser>(this); return '';
1231+
} } });
12271232
}

types/schematypes.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ declare module 'mongoose' {
8080
* The default value for this path. If a function, Mongoose executes the function
8181
* and uses the return value as the default.
8282
*/
83-
default?: DefaultType<T> | ((this: any, doc: any) => DefaultType<T>) | null;
83+
default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T>) | null;
8484

8585
/**
8686
* The model that `populate()` should use if populating this path.

0 commit comments

Comments
 (0)