objectForPrimaryKey should return null instead of undefined

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: 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
              Reporter:
              Andrew Meyer
              Archiver:
              Marc Greenfield

                Created:
                Updated:
                Resolved:
                Archived: