Skip to content

Conversation

@vanstinator
Copy link
Contributor

@vanstinator vanstinator commented Aug 4, 2023

Description

What is changing?

I've added null and undefined as new types to the otherId type union on ObjectId.equals.

Is there new documentation needed for these changes?

I don't believe so. Functionally nothing is changing about what the function is doing. We're just making the types more permissive to match the function body.

What is the motivation for this change?

We've been migrating away from a custom idEquals function in a large codebase towards ObjectId.equals. Our custom function allowed for undefined ids and it looks like .equals allows for them as well when reading the function body, but the Typescript definition doesn't include undefined or null in the type union. This blocks the ability to pass a potentially undefined ObjectId to .equals and leads to awkward ternaries or other hacks that shouldn't be necessary from the caller.

Release Highlight

Fill in title or leave empty for no highlight

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@vanstinator vanstinator changed the title fix(NODE-5452): Allow undefined or null params in ObjectId.equals fix(NODE-5509): Allow undefined or null params in ObjectId.equals Aug 4, 2023
@duncanbeevers
Copy link

👍 for a types-only change.

I could argue all day about the implementation, but this change makes the types match the implementation. 💯

@durran durran added the tracked-in-jira There is a ticket in Mongo's Jira instance tracking this issue/PR label Aug 7, 2023
@durran durran self-assigned this Aug 7, 2023
@durran durran merged commit e2674c6 into mongodb:main Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tracked-in-jira There is a ticket in Mongo's Jira instance tracking this issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants