Skip to content

Commit ee7f095

Browse files
authored
fix(NODE-3668): compile error with OptionalId on TS 4.5 beta (#3004)
1 parent 0a66124 commit ee7f095

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/mongo_types.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<
3838
* `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?"
3939
* we instead ask "Does ObjectId look like (have the same shape) as the _id?"
4040
*/
41-
export type OptionalId<TSchema extends { _id?: any }> = ObjectId extends TSchema['_id'] // a Schema with ObjectId _id type or "any" or "indexed type" provided
42-
? EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> } // a Schema provided but _id type is not ObjectId
43-
: WithId<TSchema>; // TODO(NODE-3285): Improve type readability
41+
export type OptionalId<TSchema> = TSchema extends { _id?: any }
42+
? ObjectId extends TSchema['_id'] // a Schema with ObjectId _id type or "any" or "indexed type" provided
43+
? EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> } // a Schema provided but _id type is not ObjectId
44+
: WithId<TSchema>
45+
: EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> }; // TODO(NODE-3285): Improve type readability
4446

4547
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
4648
export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion

0 commit comments

Comments
 (0)