Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-5790): type error with $addToSet in bulkWrite #3956

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

alenakhineika
Copy link
Contributor

@alenakhineika alenakhineika commented Jan 8, 2024

Description

Backporting #3953 to 5x.

What is changing?

We update types to fix the error with $addToSet in bulkWrite.

Is there new documentation needed for these changes?

None

What is the motivation for this change?

NODE-5647
NODE-4664

Release Highlight

The type error with $addToSet in bulkWrite was fixed

Previously the following code sample would show a type error:

interface IndexSingatureTestDocument extends Document {
    readonly myId: number;
    readonly mySet: number[];
  }
const indexSingatureCollection = undefined as unknown as Collection<IndexSingatureTestDocument>;
indexSingatureCollection.bulkWrite([
  {
    updateOne: {
      filter: { myId: 0 },
      update: {
        $addToSet: { mySet: 0 } // The type error! Type 'number' is not assignable to type 'never'.
      }
    }
  }
]);

It happened because the driver's Document type falls back to any, and internally we could not distinguish whether or not this assignment was intentional and should be allowed.

After this change, users can extend their types from Document/any, or use properties of any type and we skip the $addToSet validation in those cases.

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

@alenakhineika alenakhineika marked this pull request as ready for review January 8, 2024 16:25
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, slacked about updating release notes, I'll keep the ticket in verification until we've got that updated.

@nbbeeken nbbeeken self-assigned this Jan 8, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 8, 2024
@nbbeeken nbbeeken changed the title fix(NODE-5791): type error with $addToSet in bulkWrite fix(NODE-5790): type error with $addToSet in bulkWrite Jan 8, 2024
@nbbeeken nbbeeken merged commit f524a94 into 5.x Jan 8, 2024
25 of 28 checks passed
@nbbeeken nbbeeken deleted the NODE-5647-type-error-with-addtoset-in-bulkwrite-5x branch January 8, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants