Questions tagged [kotlin-js-interop]

62 questions
3
votes
2 answers

How to import react-bootstrap component with children into kotlin-js react app

I want to use a bootstrap Card component in a react website created with kotlin-js. The app uses kotlin-react wrapper and react-bootstrap library. react-bootstrap documentation says use to put content. This is some…
3
votes
3 answers

Kotlin/JS external declaration - "Name contains illegal chars that can't appear in JavaScript identifier"

EDIT: This is not supported yet and tracked on Kotlin YouTrack I'm trying to write a Kotlin external declaration matching the following Typescript interface (this is valid TS to represent JavaScript accesses via headers['content-length']): export…
Joffrey
  • 32,348
  • 6
  • 68
  • 100
3
votes
0 answers

Access a Library written in Kotlin from a TS Angular Webapp

I have a library written in Kotlin that I want to use from an Angular Webapp written in TypeScript, but I end up getting Uncaught Error: Error loading module 'js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior…
Chris
  • 117
  • 7
3
votes
1 answer

How to make button click listener event in Kotlin/JavaScript?

Inside IntellJ IDEA, I ve created a button in my HTML file with an id. What I'm trying to achieve is to change the header tag to "button clicked" using kotlin. Upon searching the kolinlang.org website and others resources I have trouble finding…
3
votes
4 answers

How to serialize a Map to JSON string via JSON.stringify in kotlin JS?

My example code is below: fun main(args: Array) { val testData = mapOf( "name" to "albert", "age" to 26, "work" to listOf("1", "2", "3") ) var value = JSON.stringify(testData, { _, value ->…
Albert Gao
  • 3,653
  • 6
  • 40
  • 69
3
votes
1 answer

How to set a static property on a class in Kotlin for Javascript

I have a situation where I need to define a static property on a class in Kotlin and when its compiled to Javascript have it become a true static field on that class. In this situation companion objects do not work. For example, if I have an…
Graham
  • 5,488
  • 13
  • 57
  • 92
3
votes
1 answer

Parsing JSON with Kotlin JS 'fun parse(text: String): T`?

How can I use fun parse(text: String): T to parse JSON in Kotlin JS? e.g. how can I parse this JSON string? { "couchdb": "Welcome", "version": "2.0.0", "vendor": { "name": "The Apache Software Foundation" } }
ycomp
  • 8,316
  • 19
  • 57
  • 95
3
votes
3 answers

How to represent multiple types (union types) when targeting JavaScript

What I would like to do is use a generic type that can be one of three other types. Here's an example with a function: fun get(key: String) : T where T: String, T: Number, T: Boolean {} The above code doesn't work, so how should I go about…
Graham
  • 5,488
  • 13
  • 57
  • 92
3
votes
1 answer

Is @JsName annotation required for every method?

I was trying to make NodeJs work with Kotlin for a HelloWorld example here. As per the Kotlin JS documentation, @JsName annotation is required for overloaded methods. But in my experience, it is required even for a single method. Without this…
2
votes
1 answer

Using npm dependencies in Kotlin/Js

I need to generate uuid in Kotlin/JS and looking to call uuid.v4() from Kotlin/JS. I have gone through the documentation - https://kotlinlang.org/docs/using-packages-from-npm.html and https://kotlinlang.org/docs/js-modules.html but somehow cannot…
2
votes
1 answer

How do I import and use an async JS function in Kotlin/JS?

I'm having issues importing a Javascript async function into my Kotlin code. Here is an example Javascript function : export async function signUp(email, password){ console.log("Signing Up"); try { const userCred = await…
jlengrand
  • 12,152
  • 14
  • 57
  • 87
2
votes
1 answer

Is it possible to call kotlin's js function with an interpolated string template?

Right now, IntellJ is showing a red squiggly line saying: Argument must be a string constant private fun fromEnv(name: String) { return js("process.env[${name}]") as Unit } I've searched but I have not found any similar question. Solved by…
Richard Domingo
  • 379
  • 1
  • 19
2
votes
1 answer

Using Kotlin standard library from JavaScript

I have a Kotlin function written that consumes a List. The function has an annotation with @JsName so that I can call this function from JavaScript. I cannot determine though what I am supposed to pass into this function. Passing an…
Vance T
  • 513
  • 2
  • 5
  • 15
2
votes
1 answer

Kotlin: Spread operator on calling JavaScript method

I try to write a type-safe wrapper for a JavaScript library. I need to call a method from JavaScript with variable arguments (e.g. method(args...)). The Kotlin fun for this should work with variable arguments, too. Because Kotlin supports a spread…
2
votes
3 answers

How to JavaScript object to Kotlin class?

I want to get a JavaScript object loaded into a Kotlin class. As a safety check, I need to verify that the Kotlin object is actually the class I’ve created because some JavaScript code parts are not my design. I need the JavaScript to return…
iHad 169
  • 1,267
  • 1
  • 10
  • 16