Questions tagged [kotlin-js-interop]
62 questions
1
vote
1 answer
Kotlin to Javascript file compilation
Currently, I have two .kt files in a Kotlin/JS project I'm working on. These two .kt files compile to one single .js file (the one in "out/production/myprojectfolder/myproject.js" which is the default directory).
Each of the .kt files represent two…

Femi Sotonwa
- 103
- 1
- 4
1
vote
0 answers
KotlinJs direct casts fail while generic casts work
Not sure if this is a discrepancy in the type cast or I am using it wrong. The direct cast throws an error but using generic cast will make my code work.
Below I am trying to cast a Json to Person
import kotlin.js.Json
data class Person(val…

Krishna K
- 1,925
- 1
- 14
- 11
1
vote
1 answer
Kotlin JS Overriding 'external' function with optional parameters error
I pulled in jQuery to use in my project using ts2kt. The basics work fine, however, I can't figure out how to call this function (I just want to pass a single callback to it):
fun done(doneCallback1: JQueryPromiseCallback? = definedExternally /*…

zsmb13
- 85,752
- 11
- 221
- 226
1
vote
1 answer
How to call a javascript function from Kotlin that expects a jQuery ajax settings object?
I need to convert the following code, it uses something in jQuery called an ajax settings (which is used in the javascript below inside the create() call to create a CouchDB database)
$.couch.db("mydb").create({
success: function(data) {
…

ycomp
- 8,316
- 19
- 57
- 95
0
votes
0 answers
Using Splide Javascript Library in KotlinJS frontend
I'm trying to find a kotlin based framework for a web-app and decided to try KVision as frontend framework (https://kvision.io).
I tried to use an external javascript library called Splide (https://splidejs.com) to get a slider, but I can't get it…

Woggle
- 1
- 1
0
votes
0 answers
Reference JS API from Kotlin React App which is included in index.html
I can't seem to find any information about this, and I'm not sure if this is possible.
In a standard react app, you can do something like this:
JS…

Josh
- 69
- 11
0
votes
1 answer
How to submit a form with KotlinJS and React?
I want to display a file selector and a submit button.
The file is only to be submitted once the button is clicked.
The submit/action target is on another server though.
I looked at react examples, but I can't figure out the exact method on how…

Splitframe
- 406
- 3
- 16
0
votes
1 answer
building kotlinJs app on github actions CI
I'm having some issues setting up github actions to build my kotlinJS project?
i have the js runtime dependency:
implementation(npm("kotlinx-serialization-kotlinx-serialization-core-jslegacy", "1.4.2-RC1"))
and i get error:
Module…

siliconeagle
- 7,379
- 3
- 29
- 41
0
votes
1 answer
Calling JavaScript from Kotlin
I have ReactNative project and I'm trying to call simple JS function from Kotlin (calling Kotlin from JS works fine). My project directory looks like this:
"shared" module is compiled as commonjs module.
In Main.kt I have (shortened):
external fun…

Warlock
- 2,481
- 4
- 31
- 45
0
votes
1 answer
Can't resolve 'kotlin' in '/home/marcin/Projects/EduKotlinAcademy/web/build/node_modules_imported/kotlinx-html-js'
I started Kotlin/JS react library on kotlin frontend Gradle plugin. I have the following error:
> Task :web:webpack-bundle FAILED
js/kotlinx-html-js.js
Module not found: Error: Can't resolve 'kotlin' in…

MarcinM
- 428
- 7
- 15
0
votes
2 answers
How to access Kotlin object from JavaScript
I'm using kotlin2js to generate JS library from Kotlin code. I'm then using this library in Javascript (not Kotlin). The code has some Kotlin objects and some normal classes. I can access normal classes from Javascript, but I can't access the…

David Vávra
- 18,446
- 7
- 48
- 56
0
votes
0 answers
Is there any way to write Kotlin code to generate javascript like "AppComponent.annotations"
I'm trying to use Kotlin to write angular JavaScript code. Here is some valid Javascript code for angular:
const AppComponent = function () {
this.title = 'Angular Hello World Demo'
};
AppComponent.annotations = [new ng.core.Component({
…

Freewind
- 193,756
- 157
- 432
- 708
0
votes
1 answer
Different semantics of KProperty1 in JS compared to JVM
It looks like KProperty1 has different semantics in JVM and JS e.g. while this test works on the JVM:
data class Data(val name: String)
class Test {
@Test fun propertiesMustBeEqual() {
assertEquals(Data::name, Data::name)
…

n_l
- 844
- 1
- 6
- 19
0
votes
1 answer
Creating simple Node server with Kotlin
I'm trying to create a simple Node server using Kotlin to replicate the basic sample here:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
…

Hasan A Yousef
- 22,789
- 24
- 132
- 203
0
votes
2 answers
How to properly test web socket connection with KotlinJS
I'm unable to test my code that uses a native WebSocket. This is the body of the test function:
val webSocket = WebSocket("ws://localhost:8888")
window.setTimeout({
assertEquals(WebSocket.OPEN, webSocket.readyState)
}, 1000)
I'm using Karma…

Czyzby
- 2,999
- 1
- 22
- 40