# JS / External class not converting Javascript Number to Kotlin Long

**URL:** <https://discuss.kotlinlang.org/t/js-external-class-not-converting-javascript-number-to-kotlin-long/9298>\
**Category:** Support\
**Created:** [September 2, 2018, 10:14pm UTC](https://discuss.kotlinlang.org/t/js-external-class-not-converting-javascript-number-to-kotlin-long/9298 "2018-09-02T22:14:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snorbi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@snorbi](https://discuss.kotlinlang.org/u/snorbi)\
**Post date:** [September 2, 2018, 10:14pm UTC](https://discuss.kotlinlang.org/t/js-external-class-not-converting-javascript-number-to-kotlin-long/9298/1 "2018-09-02T22:14:51Z")

</div>

I have an external JS class:

```
external class MyJsClass {
    fun number(): Long
}

```

When I try call this function, the generated code does not convert the Javascript `Number` to Kotlin `Long` but simply tries to call Kotlin functions on it, eg.

```
// Kotlin code
val a: MyJsClass = ...
val b: MyJsClass = ...
a.number().compareTo(b.number())

```

results in a `<TypeError: ... .compareTo_11rb$ is not a function>` because the generated code is simply:

```
// Javascript code
a.number().compareTo_11rb$(b.number())

```

What should I do to force the conversion to a “real” Kotlin `Long`?

---

<div class="post-metadata">

**Author:** ![snorbi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@snorbi](https://discuss.kotlinlang.org/u/snorbi)\
**Post date:** [September 3, 2018, 9:49am UTC](https://discuss.kotlinlang.org/t/js-external-class-not-converting-javascript-number-to-kotlin-long/9298/2 "2018-09-03T09:49:53Z")

</div>

Using

- `Number` instead of `Long` in the `external class` definition and
- explicitly converting to `Long`

seems to work as expected:

```
external class MyJsClass {
    fun number(): Number
}

val a: MyJsClass = ...
val b: MyJsClass = ...
a.number().toLong().compareTo(b.number().toLong())

```

_(Edited the original post to match the examples.)_
