Hi everyone! I updated Kotlin today and I’m runnin...
# javascript
d
Hi everyone! I updated Kotlin today and I’m running into some issues. In my project, code like this used to run fine but I’m now getting an
TypeError: ArrayList_init_0 is not a function
runtime error.
Copy code
console.log("here")
val jsArray = js("[1,2,3]") as Array<Int>
val result = jsArray.filter { it < 5 }
The project compiles without problems and Intellij shows no warnings. Has anybody else experienced similar issues or has any ideas how to resolve this?
h
is there any reason you need an array with javascript? if you create it with kotlin, it will be compiled into an array anyways
d
The reason I do this is that I fetch a JSON API response into a dynamic variable and then cast it into a class (probably a bad way to this anyway). Here is an example:
Copy code
class TestApiResponse(val testArray: Array<Int>)

    val apiResponse: TestApiResponse = js("{ testArray: [1,2,3,4] }")
    console.log(apiResponse.testArray.filter { it > 2 })
h
im not too good at js, so take my advice with a grain of salt. couldn’t you just create the class and make it a dynamic type
d
I thought that the Kotlin Array is the representation of the standard js array.
I can think of a couple of ways to avoid this but the main problem is that I relied on Array<T> in Kotlin being the representation of the standard js array in multiple sections of the app and it is hard to find each occurrence of this issue since I’m not getting compiler errors.
I’m just wondering if this change is intended and I need to rework these sections of the project of if this is some sort of regression
Never mind, looks like I did not correctly update all dependencies. Seems like this was the issue: https://youtrack.jetbrains.com/issue/KT-26117