Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3761

OptionalId should resolve optional custom types to the user type or ObjectId

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: TypeScript
    • Labels:
    • 0
    • Not Needed

      What problem are you facing?

      this:

      expectType<OptionalId<{ _id?: number; a: number }>>({ a: 3 });
      

      is a failure because it requires _id: ObjectId

      It should be _id?: number | ObjectId.

      I believe the fix should target the logic in InferIdType adding a condition that checks for "optional" and returns the union mentioned above instead.

      Alternatively, we could try to forbid users from defining an optional _id that is not an ObjectId, since otherwise they could inadvertently introduce inconsistencies into their database by omitting the _id which would result in the database generating an ObjectId as the value.

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: