Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1322

objectForPrimaryKey should return null instead of undefined

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      Problem

      When an object is not found with objectForPrimaryKey, undefined is returned. This is syntactically not correct. It should return a null value, since the object does not exist. undefined should be reserved for unset properties.

      Solution

      Change the implementation of objectForPrimaryKey to return null.
      Update the types as follows:

      objectForPrimaryKey<T>(type: string, key: Realm.PrimaryKey): (T & Realm.Object) | null;
      objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: Realm.PrimaryKey): T | null;
      

      How important is this improvement for you?

      I'd like to see it, but have a workaround

            Assignee:
            andrew.meyer@mongodb.com Andrew Meyer
            Reporter:
            andrew.meyer@mongodb.com Andrew Meyer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: