```fun testFun(value: Any) { println("Value $v...
# javascript
p
Copy code
fun testFun(value: Any) {
    println("Value $value is of type ${value::class.simpleName}")
}

val v: Double = 1.0
testFun(v) // will print: Value 1 is of type Int  // why?
r
The body of the function is translated to this JavaScript code:
Copy code
println('Value ' + toString(value) + ' is of type ' + getKClassFromExpression(value).get_simpleName_r6f8py_k$());
The type is "guessed" from the value. And 1.0 is integer in JavaScript.
p
Is there any workaround for this case?
r
fun testFun(value: Double)
will work as expected but I understand it's not a solution for your case?
This behavior of K/JS is documented here (at the bottom of the page): https://kotlinlang.org/docs/js-to-kotlin-interop.html#kotlin-types-in-javascript
This seems to work:
Copy code
inline fun<reified T : Any> testFun(value: T) {
    println("Value $value is of type ${value::class.simpleName}")
}
p
Thanks, Robert! I understand the problem. But in my case it comes from many layers, so I can't statically determine the type. Will think how to rework my code to handle it correctly.