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

Using dot notation with variables requires `as const` for types to match

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Not Needed
    • Not Needed

      What problem are you facing?

      When using dot notation on a find or update filter, if your string includes a variable, the type will not match as the full string is interpreted as a regular string and not a constant one, thus requiring the `as const` type assertion. This also happens if your variable is strictly typed, that means that it's not typed as `string` but the values it can actually have are explicitly typed. Here's an example:

      What driver and relevant dependency versions are you using?

      4.11.0

      Steps to reproduce?

      1. Have a collection's type include an object with explicitly typed properties
      2. Try to modify one of those properties by using dot notation on an updateOne operation
      3. Change one of the properties and use a variable to type it instead
      4. Notice the type error

        1. image-2022-11-03-18-39-55-222.png
          image-2022-11-03-18-39-55-222.png
          2 kB
        2. image-2022-11-03-18-40-19-399.png
          image-2022-11-03-18-40-19-399.png
          5 kB
        3. image-2022-11-03-18-40-38-518.png
          image-2022-11-03-18-40-38-518.png
          4 kB
        4. image-2022-11-03-18-41-37-178.png
          image-2022-11-03-18-41-37-178.png
          3 kB
        5. image-2022-11-03-18-43-21-364.png
          image-2022-11-03-18-43-21-364.png
          18 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            rodrigoleitao25@gmail.com Rodrigo Leitão
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: