File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1- import { MergeType } from 'mongoose' ;
1+ import { MergeType , WithTimestamps } from 'mongoose' ;
22import { expectType } from 'tsd' ;
33
44type A = { a : string , c : number } ;
@@ -11,3 +11,21 @@ expectType<number>({} as MergeType<B, A>['c']);
1111expectType < number > ( { } as MergeType < A , B > [ 'a' ] ) ;
1212expectType < string > ( { } as MergeType < A , B > [ 'b' ] ) ;
1313expectType < number > ( { } as MergeType < A , B > [ 'c' ] ) ;
14+
15+ type C = WithTimestamps < { a : string ; b : string } > ;
16+ expectType < string > ( { } as C [ 'a' ] ) ;
17+ expectType < string > ( { } as C [ 'b' ] ) ;
18+ expectType < Date > ( { } as C [ 'createdAt' ] ) ;
19+ expectType < Date > ( { } as C [ 'updatedAt' ] ) ;
20+
21+ type D = WithTimestamps <
22+ { a : string ; b : string } ,
23+ {
24+ createdAt : 'created' ;
25+ updatedAt : 'modified' ;
26+ }
27+ > ;
28+ expectType < string > ( { } as D [ 'a' ] ) ;
29+ expectType < string > ( { } as D [ 'b' ] ) ;
30+ expectType < Date > ( { } as D [ 'created' ] ) ;
31+ expectType < Date > ( { } as D [ 'modified' ] ) ;
Original file line number Diff line number Diff line change @@ -93,4 +93,12 @@ type AddThisParameter<T, D> = {
9393 : T [ K ] ;
9494} ;
9595
96+ /**
97+ * @summary Adds timestamp fields to a type
98+ * @description Adds createdAt and updatedAt fields of type Date, or custom timestamp fields if specified
99+ * @param {T } T The type to add timestamp fields to
100+ * @param {P } P Optional SchemaTimestampsConfig or boolean to customize timestamp field names
101+ * @returns T with timestamp fields added
102+ */
103+ export type WithTimestamps < T , P extends SchemaTimestampsConfig | boolean = true > = ResolveTimestamps < T , { timestamps : P } > ;
96104}
You can’t perform that action at this time.
0 commit comments