diff --git a/src/mongo_types.ts b/src/mongo_types.ts index cc73d0d63b..e911aade8c 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -38,9 +38,11 @@ export type WithId = EnhancedOmit & { _id: InferIdType< * `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?" * we instead ask "Does ObjectId look like (have the same shape) as the _id?" */ -export type OptionalId = ObjectId extends TSchema['_id'] // a Schema with ObjectId _id type or "any" or "indexed type" provided - ? EnhancedOmit & { _id?: InferIdType } // a Schema provided but _id type is not ObjectId - : WithId; // TODO(NODE-3285): Improve type readability +export type OptionalId = TSchema extends { _id?: any } + ? ObjectId extends TSchema['_id'] // a Schema with ObjectId _id type or "any" or "indexed type" provided + ? EnhancedOmit & { _id?: InferIdType } // a Schema provided but _id type is not ObjectId + : WithId + : EnhancedOmit & { _id?: InferIdType }; // TODO(NODE-3285): Improve type readability /** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */ export type EnhancedOmit = string extends keyof TRecordOrUnion