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

XMLWordPrintableJSON

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

      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
            Reporter:
            Neal Beeken
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: