Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 48 additions & 24 deletions docs/topics/js/js-to-kotlin-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,59 @@ kotlin {

2. Enable the `BigInt` type. See how to enable it in [Use of `BigInt` type to represent Kotlin's `Long` type](#use-bigint-type-to-represent-kotlin-s-long-type).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not about the change, but for consistency: The link text does not match the corresponding heading, should it? Both are grammatically correct, it just looks odd that they are different.


### Use `BigInt64Array` type to represent Kotlin's `LongArray` type
<primary-label ref="experimental-general"/>

Kotlin/JS uses JavaScript's built-in `BigInt64Array` type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I need to enable this feature, it should probably be "can use", not "uses"?

to represent Kotlin's `LongArray` values when compiling to JavaScript.

To enable support for the `BigInt64Array` type, you need to add the following compiler option to your
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To enable support for the `BigInt64Array` type, you need to add the following compiler option to your
To enable support for the `BigInt64Array` type, add the following compiler option to your

`build.gradle(.kts)` file:

```kotlin
// build.gradle.kts
kotlin {
js {
...
compilerOptions {
freeCompilerArgs.add("-Xes-long-as-bigint")
}
}
}
```

This feature is [Experimental](components-stability.md#stability-levels-explained). Share your feedback in our issue tracker,
[YouTrack](https://youtrack.jetbrains.com/issue/KT-79284/Use-BigInt64Array-for-LongArray).

## Kotlin types in JavaScript

See how Kotlin types are mapped to JavaScript ones:

| Kotlin | JavaScript | Comments |
|------------------------------------------------------------------|---------------------------|---------------------------------------------------------------------------------------|
| `Byte`, `Short`, `Int`, `Float`, `Double` | `Number` | |
| `Char` | `Number` | The number represents the character's code. |
| Kotlin | JavaScript | Comments |
|------------------------------------------------------------------|---------------------------|---------------------------------------------------------------------------------------------------------|
| `Byte`, `Short`, `Int`, `Float`, `Double` | `Number` | |
| `Char` | `Number` | The number represents the character's code. |
| `Long` | `BigInt` | Needs the [`-Xes-long-as-bigint` compiler option](compiler-reference.md#xes-long-as-bigint) configured. |
| `Boolean` | `Boolean` | |
| `String` | `String` | |
| `Array` | `Array` | |
| `ByteArray` | `Int8Array` | |
| `ShortArray` | `Int16Array` | |
| `IntArray` | `Int32Array` | |
| `CharArray` | `UInt16Array` | Carries the property `$type$ == "CharArray"`. |
| `FloatArray` | `Float32Array` | |
| `DoubleArray` | `Float64Array` | |
| `LongArray` | `Array<kotlin.Long>` | Carries the property `$type$ == "LongArray"`. Also see Kotlin's Long type comment. |
| `BooleanArray` | `Int8Array` | Carries the property `$type$ == "BooleanArray"`. |
| `List`, `MutableList` | `KtList`, `KtMutableList` | Exposes an `Array` via `KtList.asJsReadonlyArrayView` or `KtMutableList.asJsArrayView`. |
| `Map`, `MutableMap` | `KtMap`, `KtMutableMap` | Exposes an ES2015 `Map` via `KtMap.asJsReadonlyMapView` or `KtMutableMap.asJsMapView`. |
| `Set`, `MutableSet` | `KtSet`, `KtMutableSet` | Exposes an ES2015 `Set` via `KtSet.asJsReadonlySetView` or `KtMutableSet.asJsSetView`. |
| `Unit` | Undefined | Exportable when used as return type, but not when used as parameter type. |
| `Any` | `Object` | |
| `Throwable` | `Error` | |
| `enum class Type` | `Type` | Enum entries are exposed as static class properties (`Type.ENTRY`). |
| Nullable `Type?` | `Type | null | undefined` | |
| All other Kotlin types, except for those marked with `@JsExport` | Not supported | Includes Kotlin's [unsigned integer types](unsigned-integer-types.md). |
| `Boolean` | `Boolean` | |
| `String` | `String` | |
| `Array` | `Array` | |
| `ByteArray` | `Int8Array` | |
| `ShortArray` | `Int16Array` | |
| `IntArray` | `Int32Array` | |
| `CharArray` | `UInt16Array` | Carries the property `$type$ == "CharArray"`. |
| `FloatArray` | `Float32Array` | |
| `DoubleArray` | `Float64Array` | |
| `LongArray` | `BigInt64Array` | |
| `BooleanArray` | `Int8Array` | Carries the property `$type$ == "BooleanArray"`. |
| `List`, `MutableList` | `KtList`, `KtMutableList` | Exposes an `Array` via `KtList.asJsReadonlyArrayView` or `KtMutableList.asJsArrayView`. |
| `Map`, `MutableMap` | `KtMap`, `KtMutableMap` | Exposes an ES2015 `Map` via `KtMap.asJsReadonlyMapView` or `KtMutableMap.asJsMapView`. |
| `Set`, `MutableSet` | `KtSet`, `KtMutableSet` | Exposes an ES2015 `Set` via `KtSet.asJsReadonlySetView` or `KtMutableSet.asJsSetView`. |
| `Unit` | Undefined | Exportable when used as return type, but not when used as parameter type. |
| `Any` | `Object` | |
| `Throwable` | `Error` | |
| `enum class Type` | `Type` | Enum entries are exposed as static class properties (`Type.ENTRY`). |
| Nullable `Type?` | `Type | null | undefined` | |
| All other Kotlin types, except for those marked with `@JsExport` | Not supported | Includes Kotlin's [unsigned integer types](unsigned-integer-types.md). |

Additionally, it is important to know that:

Expand Down