Is it by design, that `Array.isArray()` returns `...
# javascript
i
Is it by design, that
Array.isArray()
returns
false
for an instance returned by
KtList.asJsReadonlyArrayView()
? I'm trying to migrate classes from
Array
to
List
but I use
Array.isArray
quite frequently so this a bit annoying. I checked the JS exported source of the stdlib, and this could be fixed by replacing
new Proxy(arrayView, ...)
with
new Proxy([], ...)
here:
Copy code
function createJsArrayViewWith(listSize, listGet, listSet, listDecreaseSize, listIncreaseSize) {
  var arrayView = objectCreate(protoOf(JsArrayView));
  return new Proxy(arrayView, {get: function (target, prop, receiver) {
My current workaround is to proxy the proxy:
Copy code
function proxy<E>(arg: ReadonlyArray<E>) { return new Proxy([], {
  get(_target, prop: any, _receiver) {
    return arg[prop];
  },
  has(_target, prop: any) {
    return prop in arg;
  }
})}
👌 1
1
a
Could you please create an ticket on YouTrack for it, and I will try to change it ASAP
🎉 1
i
e
Note that you might face this issue using the new collections export. https://youtrack.jetbrains.com/issue/KT-69353 In case it happens, you can add a
doLast
step to the link task to enhance the .d.ts file
Copy code
binaries.withType<JsIrBinary>().configureEach {
  linkTask.configure {
    doLast { ... }
  }
}
👍 1
i
e
Thanks! I'm happy to see those issues reported, means people are actually using new JS features. Devs will be less happy tho 😂
I'm still locked to 1.9.24, so I hope by 2.1 everything will be ironed out.
i
I'm really happy with these improvements like the ability to use collections in exported API and the upcoming @JsStatic. And I think these issues can be fixed quickly
1
BTW I'd be happy to contribute if that is possible in any way.
e
I think it's better to ask in the issue if opening a PR is ok first, to sync with Kotlin's devs. I've seen other people opening PRs and those be ignored for a long time. Also, you need to know how to add JS tests to verify the compiled code.