Hey guys, I’m compiling a lib that is supposed to ...
# javascript
s
Hey guys, I’m compiling a lib that is supposed to be consumed by TypeScript. How do I export a
Long
to JS with the IR compiler ???
Copy code
@JsExport
fun long(): Long = 0x12_34_56_78_9A_BC_DE_F0
Calling this
long
function with typescript returns the following object:
Long { _low: -1698898192, _high: 305419896 }
Casting to int does NOT do the trick as the compiler overflows :
Copy code
@JsExport
fun int(): Int = 0x12_34_56_78_9A_BC_DE_F0.toInt()
Calling this
int
function with typescript returns a negative number:
-1698898192
How can I export a
Long
?
h
JavaScript does not have a
Long
implementation.
s
Often a double is good enough. It can represent intergers up to ~54bits
s
That’s untrue. JavaScript can natively handle 8 bytes numbers, such as
9223372036854775
, which is way over
Int.MAX_VALUE
. Running in node:
Copy code
let n = 9223372036854775
n = n + 1
Gives the correct value
s
s
Thanks Johannes, that’s exactly what I needed 😉