From 19b6d4a231a67f89f6f3e87d4b38fc418d8fdd52 Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Thu, 7 Jul 2022 12:20:24 +0800 Subject: [PATCH] fix(types): allow using an object to configure timestamps This is a documented feature. Users should be able to configure createdAt and updatedAt separately when making a query from TypeScript. --- types/models.d.ts | 2 +- types/query.d.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/types/models.d.ts b/types/models.d.ts index 446a5c14da7..5166f47613f 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -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; diff --git a/types/query.d.ts b/types/query.d.ts index 5468cf68ec9..899ce9b29c6 100644 --- a/types/query.d.ts +++ b/types/query.d.ts @@ -90,6 +90,11 @@ declare module 'mongoose' { [key: string]: any; }; + interface QueryTimestampsConfig { + createdAt?: boolean; + updatedAt?: boolean; + } + interface QueryOptions extends PopulateOption, SessionOption { @@ -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;