Skip to content

Commit

Permalink
fix(types): allow using an object to configure timestamps
Browse files Browse the repository at this point in the history
This is a documented feature. Users should be able to configure
createdAt and updatedAt separately when making a query from TypeScript.
  • Loading branch information
lantw44 committed Jul 7, 2022
1 parent a1d88e5 commit 19b6d4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion types/models.d.ts
Expand Up @@ -106,7 +106,7 @@ declare module 'mongoose' {
checkKeys?: boolean;
j?: boolean;
safe?: boolean | WriteConcern;
timestamps?: boolean;
timestamps?: boolean | QueryTimestampsConfig;
validateBeforeSave?: boolean;
validateModifiedOnly?: boolean;
w?: number | string;
Expand Down
7 changes: 6 additions & 1 deletion types/query.d.ts
Expand Up @@ -90,6 +90,11 @@ declare module 'mongoose' {
[key: string]: any;
};

interface QueryTimestampsConfig {
createdAt?: boolean;
updatedAt?: boolean;
}

interface QueryOptions<DocType = unknown> extends
PopulateOption,
SessionOption {
Expand Down Expand Up @@ -157,7 +162,7 @@ declare module 'mongoose' {
* skip timestamps for this update. Note that this allows you to overwrite
* timestamps. Does nothing if schema-level timestamps are not set.
*/
timestamps?: boolean;
timestamps?: boolean | QueryTimestampsConfig;
upsert?: boolean;
writeConcern?: mongodb.WriteConcern;

Expand Down

0 comments on commit 19b6d4a

Please sign in to comment.