I have a couple of question to the kotlin team 1....
# javascript
a
I have a couple of question to the kotlin team 1. Is there a reason why the Kotlin
Long
object is not mapped to Javascript's
BigInt
? 2. Is there a reason why Kotlin
Number
is not mapped to Javascript's
Number
3. Is there a reason why Kotlin
Map
and
Set
are not mapped to Javascript's
Map
and
Set
respectively?
j
What would mapping to BigInt help with? You would still have to implement nearly every mathematical operation yourself in order to preserve 64-bit semantics
BigInt is dog slow and it would be unfortunate to penalize all computations on Long especially since most are likely to rarely exceed the lower 32-bits
e
Kotlin/JS doesn't even target ES6 yet: https://youtrack.jetbrains.com/issue/KT-8373 and BigInt comes in ES11
JS Number cannot represent all Kotlin Number (a JS BigInt is not a JS Number) so I'm not sure why you think that mapping kotlin.Number to JS Number would help
presumably Map and Set could be added once Kotlin/JS targets ES6, but it doesn't
(I'm not Kotlin team but that all seems reasonable to me)
a
Didn't really know BigInt is "dog slow" as Jake put it
Js BigInt is not a JS Number
For some funky reasons, that makes sense to me now why Number should't be exported to Js Number
Fingers crossed. Waiting for ES6
j
nice link
g
Does it make sense for you guys to have a Long in KMP project (Android/iOS/Web) and a facade for jsMain that converts with toDouble() to get a Js Number? (I know that computes will lost precision at some point)
e
BigInt at the interop interface boundaries might make sense, although I think it depends on what you are doing with it. if it's being passed between Kotlin and something that is ultimately JSON without arithmetic on the JS side, it would be easier to just stringify/parse on the Kotlin side. I do not like the idea of using Double, since that will allow you to unwittingly perform unsafe operations, whereas a string is more opaque
t
1.
Map
and
Set
in Kotlin are interfaces with multiple implementations and you can write your own implementation 2. In JS
Map
and
Set
and classes, which use other key equality rules 3. You can find direct analog for JS class (
Array
,
String
), but not for interface