diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 1924b2afe2..0f878041e0 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -219,7 +219,7 @@ export type NotAcceptedFields = { /** @public */ export type OnlyFieldsOfType = IsAny< TSchema[keyof TSchema], - Record, + AssignableType extends FieldType ? Record : Record, AcceptedFields & NotAcceptedFields & Record diff --git a/test/types/community/collection/updateX.test-d.ts b/test/types/community/collection/updateX.test-d.ts index 5ea59cd525..c2fb170b74 100644 --- a/test/types/community/collection/updateX.test-d.ts +++ b/test/types/community/collection/updateX.test-d.ts @@ -60,6 +60,13 @@ expectAssignable>({ $inc: { anyKeyWhatsoever: 2 } }); // But this no longer asserts anything about what the original keys map to expectNotType>({ $inc: { numberField: '2' } }); +expectAssignable>({ + $currentDate: { anyKeyWhatsoever: { $type: 'timestamp' } } +}); +expectAssignable>({ $currentDate: { anyKeyWhatsoever: { $type: 'date' } } }); +expectAssignable>({ $currentDate: { anyKeyWhatsoever: true } }); +expectNotType>({ $currentDate: { anyKeyWhatsoever: 'true' } }); +expectNotType>({ $currentDate: { anyKeyWhatsoever: { key2: true } } }); // collection.updateX tests const client = new MongoClient(''); const db = client.db('test'); diff --git a/test/types/helper_types.test-d.ts b/test/types/helper_types.test-d.ts index f5df10de56..ce8fbfce0f 100644 --- a/test/types/helper_types.test-d.ts +++ b/test/types/helper_types.test-d.ts @@ -69,6 +69,9 @@ expectAssignable>({ a: 2 }); expectAssignable>({ b: 'hello' }); expectAssignable>({ b: true }); +// test the case in which AssignableType does not inherit from FieldType, and AssignableType is provided +expectAssignable>({ b: false }); + // test generic schema, essentially we expect nearly no safety here expectAssignable>({ someKey: 2 }); // We can still at least enforce the type that the keys map to