diff --git a/docs/topics/js/js-to-kotlin-interop.md b/docs/topics/js/js-to-kotlin-interop.md index ea2b4e37170c..35f110aa029a 100644 --- a/docs/topics/js/js-to-kotlin-interop.md +++ b/docs/topics/js/js-to-kotlin-interop.md @@ -120,34 +120,9 @@ the JavaScript target, and allows you to also export Kotlin declarations that ar ## 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. | -| `Long` | Not supported | There is no 64-bit integer number type in JavaScript, so it is emulated by a Kotlin class. | -| `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` | Carries the property `$type$ == "LongArray"`. Also see Kotlin's Long type comment. | -| `BooleanArray` | `Int8Array` | Carries the property `$type$ == "BooleanArray"`. | -| `Unit` | Undefined | | -| `Any` | `Object` | | -| `Throwable` | `Error` | | -| Nullable `Type?` | `Type \| null \| undefined` | | -| All other Kotlin types (except for those marked with `JsExport` annotation) | Not supported | Includes Kotlin's collections (`List`, `Set`, `Map`, etc.), and unsigned variants. | - -Additionaly, it is important to know that: - -* Kotlin preserves overflow semantics for `kotlin.Int`, `kotlin.Byte`, `kotlin.Short`, `kotlin.Char` and `kotlin.Long`. -* Kotlin cannot distinguish between numeric types at runtime (except for `kotlin.Long`), so the following code works: +* Kotlin numeric types, except for `kotlin.Long` are mapped to JavaScript `Number`. +* `kotlin.Char` is mapped to JavaScript `Number` representing character code. +* Kotlin can't distinguish between numeric types at run time (except for `kotlin.Long`), so the following code works: ```kotlin fun f() { @@ -157,5 +132,22 @@ Additionaly, it is important to know that: } ``` +* Kotlin preserves overflow semantics for `kotlin.Int`, `kotlin.Byte`, `kotlin.Short`, `kotlin.Char` and `kotlin.Long`. +* `kotlin.Long` is not mapped to any JavaScript object, as there is no 64-bit integer number type in JavaScript. It is emulated by a Kotlin class. +* `kotlin.String` is mapped to JavaScript `String`. +* `kotlin.Any` is mapped to JavaScript `Object` (`new Object()`, `{}`, and so on). +* `kotlin.Array` is mapped to JavaScript `Array`. +* Kotlin collections (`List`, `Set`, `Map`, and so on) are not mapped to any specific JavaScript type. +* `kotlin.Throwable` is mapped to JavaScript Error. * Kotlin preserves lazy object initialization in JavaScript. * Kotlin does not implement lazy initialization of top-level properties in JavaScript. + +### Primitive arrays + +Primitive array translation utilizes JavaScript `TypedArray`: + +* `kotlin.ByteArray`, `-.ShortArray`, `-.IntArray`, `-.FloatArray`, and `-.DoubleArray` are mapped to + JavaScript `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, and `Float64Array` correspondingly. +* `kotlin.BooleanArray` is mapped to JavaScript `Int8Array` with a property `$type$ == "BooleanArray"`. +* `kotlin.CharArray` is mapped to JavaScript `UInt16Array` with a property `$type$ == "CharArray"`. +* `kotlin.LongArray` is mapped to JavaScript `Array` of `kotlin.Long` with a property `$type$ == "LongArray"`. \ No newline at end of file