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

Cannot assign to <field> because it is a read-only property.ts(2540)

    • 2

      What problem are you facing?

      I'm unable to conditionally assign fields that exist on the type. A "work around", or more specifically an alternate way of assignment, is shown in the code sample below that solves this issue. However I would like to not have to use the spread operator if I don't need to and its simply an unexpected behavior, especially since fields that don't exist the type work fine.

      What driver and relevant dependency versions are you using?

      Node.js driver 5.1.0

      Steps to reproduce?

      ```ts
      interface User

      { age: number; }

      const update: UpdateFilter<User> = {}
      update.$inc = {}
      update.$inc.age = 1 // Cannot assign to 'age' because it is a read-only property.ts(2540)
      update.$inc.level= 0 // Works
      update.$inc = { age: 1 } // Works```

            Assignee:
            Unassigned Unassigned
            Reporter:
            developer.lenneth@gmail.com Lenny Elzey
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: