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

Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'.

      How frequently does the bug occur?

      Always

      Description

      Creating a class with one property being an array of strings for which I used the RealmList<string> type. I expect the interface, schema and constructor to work together and be compatible but the types don't match up.

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'.
        Type 'List<string>' is missing the following properties from type '(string | Unmanaged<string, never>)[]': reverse, sort, fill, copyWithin, and 6 more.ts(2322)
      

      Can you reproduce the bug?

      Always

      Reproduction Steps

      I write a class like in the example below.

      export class MyClass extends Realm.Object<MyClass> {
         myClassId: string;
         ...
        images!: Realm.List<string>;
         ...
      
      public static schema: Realm.ObjectSchema = {
      name: 'MyClass',
          primaryKey: 'myClassId',
          properties: {
            myClassId: string,
         ...
            images: { type: 'list', objectType: 'string', optional: false },
         ...
          }
        }
       constructor(realm: Realm, properties: Partial<Report>) {
          super(realm, {
             myClassId: properties.myClassId || new BSON.ObjectID().toString(),
         ...
             images: properties.images || new Realm.List<string[]>(),
         ...
      

      I set a default value in the constructor resulting in this error.

      Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'.
        Type 'List<string>' is missing the following properties from type '(string | Unmanaged<string, never>)[]': reverse, sort, fill, copyWithin, and 6 more.ts(2322)
      

      What is funny is even though I define the property as realm list and I construct it as such it somehow complains that it ought be 'unmanaged' and unmanaged is not well documented as far as I can tell. If I am doing something wrong I would at like the documentation to be clearer on (1) best practices or (im)possibilities of creating string arrays as properties and (2) creating default values in typescript esp. complex types such as realm lists and embedded objects.

      Version

      "realm": "^12.3.1",
      

      What services are you using?

      Local Database only

      Are you using encryption?

      Yes

      Platform OS and version(s)

      iOS 17, expo 48

      Build environment

      No response

      Cocoapods version

      No response

      edited example code

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: