Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1746,3 +1746,12 @@ async function schemaDouble() {
const doc = await TestModel.findOne().orFail();
expectType<Types.Double | null | undefined>(doc.balance);
}

function defaultReturnsUndefined() {
const schema = new Schema<{ arr: number[] }>({
arr: {
type: [Number],
default: () => void 0
}
});
}
2 changes: 1 addition & 1 deletion types/schematypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ declare module 'mongoose' {
* The default value for this path. If a function, Mongoose executes the function
* and uses the return value as the default.
*/
default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T>) | null;
default?: DefaultType<T> | ((this: EnforcedDocType, doc: any) => DefaultType<T> | null | undefined) | null;

/**
* The model that `populate()` should use if populating this path.
Expand Down
Loading