https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • v

    Vampire

    08/21/2020, 11:05 AM
    How do I formulate this in Kotlin/JS?
    try {
        /* ... */
    } catch (error) {
        if (error.name === cache.ValidationError.name) {
            throw error
        } else if (error.name === cache.ReserveCacheError.name) {
            <http://core.info|core.info>(error.message)
        } else {
            core.warning(error.message)
        }
    }
    t
    t
    u
    • 4
    • 30
  • b

    Big Chungus

    08/21/2020, 5:14 PM
    Are tailrec functions supported on js already?
    r
    • 2
    • 1
  • v

    Victor Harlan Lacson

    08/21/2020, 10:01 PM
    Hello Im using kotin muti-platform targetting javascript and java using kotlin 1.4 and using the new
    ir
    compiler. I encounterd an issue when exporting a class with @JsExport. this happens when a class contains a field of another class
    Can't find name for declaration FUN SYNTHESIZED_DECLARATION name:B$Create$ visibility:public modality:FINAL <> (id:<http://kotlin.Int|kotlin.Int>, a:A)
    and this when i have an empty constructor on class A
    Can't find name for declaration FUN SYNTHESIZED_DECLARATION name:Item_init_$Create$ visibility:public modality:FINAL <> () returnType:B
    for example
    @JsExport
    data class A(val id: Int, val some: String)
    @JsExport
    data class B(val id: Int , val a: A?) {
     @JsName("empty_constructor")
     constuctor(): this(0,null)
    }
    would realy appreciate some work around
    t
    a
    • 3
    • 2
  • f

    fkrauthan

    08/22/2020, 4:41 AM
    Anyone ever used manual coroutines in javascript where you manually dispatch the resume method? E.g. to accomplish some sort of fake multithreading?
    v
    • 2
    • 1
  • t

    turansky

    08/22/2020, 11:46 AM
    @Jorrit
    val myDynamicConstructor = ... // for class T
    val myClass = myDynamicConstructor.unsafeCast<JsClass<T>>()
    val t: T = myClass.newInstance()
    j
    • 2
    • 3
  • g

    Gunslingor

    08/22/2020, 2:32 PM
    How does one deal with dashes in variable names in KJS?
    `grapesjs-lory-slider` = jsObject<dynamic> {
    "name contains illegal identifiers that can't appear in javascript identifiers" In JS it works like this:
    'grapesjs-lory-slider': {
                sliderBlock: {
                  category: 'Extra'
                }
    b
    • 2
    • 20
  • i

    iari

    08/23/2020, 9:53 AM
    Trying to update to 1.4
    plugins {
        kotlin("js") version "1.4.0"
    }
    results in
    Error resolving plugin [id: 'org.jetbrains.kotlin.js', version: '1.4.0']
    for me.
    t
    i
    n
    • 4
    • 14
  • g

    Gunslingor

    08/23/2020, 3:48 PM
    Not sure why can't figure this out, how do I do alert/confirm type JS function? js("alert('Hello from Kotlin')") works but shouldn't there be an alert function somewhere already?
    a
    • 2
    • 2
  • g

    Gunslingor

    08/24/2020, 1:33 AM
    I can't remember/figure out what this means in js, nor how the heck to do it in kotlin JS. I think this would effectively be overloading or overriding the jquery selector (in a function usually not globally)
    const $ = Backbone.$;
    //JS Example
    or
    val $ = Grapes.$;
    //KotlinJS Where Grapes is an External Object.
    • 1
    • 2
  • g

    Gunslingor

    08/24/2020, 4:39 PM
    I saw this in an example... brings up a question, how does one change an external interface declared already? The examples just seem to show inheritance.
    // Simple warn notifier
          var origWarn = console.warn;
          toastr.options = {
            closeButton: true,
            preventDuplicates: true,
            showDuration: 250,
            hideDuration: 150
          };
          console.warn = function (msg) {
            if (msg.indexOf('[undefined]') == -1) {
              toastr.warning(msg);
            }
            origWarn(msg);
          };
    b
    • 2
    • 23
  • m

    mohamadreza jafarzade

    08/24/2020, 8:04 PM
    Hi everyone. can i have a kotlin class that i call its method from both react js and java class?
    t
    • 2
    • 2
  • g

    Gunslingor

    08/25/2020, 2:16 AM
    Can anyone see what is wrong with this conversion of JS to to KJS? var title is where I think the problem is. JS
    // Add and beautify tooltips
          [['sw-visibility', 'Show Borders'], ['preview', 'Preview'], ['fullscreen', 'Fullscreen'],
           ['export-template', 'Export'], ['undo', 'Undo'], ['redo', 'Redo'],
           ['gjs-open-import-webpage', 'Import'], ['canvas-clear', 'Clear canvas']]
          .forEach(function(item) {
            pn.getButton('options', item[0]).set('attributes', {title: item[1], 'data-tooltip-pos': 'bottom'});
          });
          [['open-sm', 'Style Manager'], ['open-layers', 'Layers'], ['open-blocks', 'Blocks']]
          .forEach(function(item) {
            pn.getButton('views', item[0]).set('attributes', {title: item[1], 'data-tooltip-pos': 'bottom'});
          });
          var titles = document.querySelectorAll('*[title]');
    
          for (var i = 0; i < titles.length; i++) {
            var el = titles[i];
            var title = el.getAttribute('title');
            title = title ? title.trim(): '';
            if(!title)
              break;
            el.setAttribute('data-tooltip', title);
            el.setAttribute('title', '');
          }
    KJS
    val toolTips = arrayOf(
            arrayOf("sw-visibility", "Show Borders"),
            arrayOf("preview", "Preview"),
            arrayOf("fullscreen", "Fullscreen"),
            arrayOf("export-template", "Export"),
            arrayOf("undo", "Undo"),
            arrayOf("redo", "Redo"),
            arrayOf("gjs-open-import-webpage", "Import"),
            arrayOf("canvas-clear", "Clear canvas")
        )
        toolTips.forEach {
            val openTmBtn = panels.getButton("views", "open-tm")
            openTmBtn.set("title", it[1])
            openTmBtn.set("data-tooltip-pos", "bottom")
        }
        val titles = document.querySelectorAll("*[title]")
        for(index in 0..titles.length) {
            val el = titles.item(index)
            var title = el?.parentElement?.getAttribute("title")?.trim() ?: ""
            if(title.isNotEmpty()) {
                el?.parentElement?.setAttribute("data-tooltip", title)
                el?.parentElement?.setAttribute("title", "")
            }
        }
    • 1
    • 2
  • g

    Gunslingor

    08/25/2020, 2:20 PM
    Sorry, pinning that to the channel was accidental, wasn't even aware it was possible!
    m
    • 2
    • 2
  • j

    Jorrit

    08/25/2020, 5:19 PM
    How do I force "require" a module when a function is called, for npm-provided polyfills?
    @SomethingGoesHere?
    external fun polyfilled(args: Int)
    Using @JsModule("npmmodule") at least doesn't work, there's no
    require('npmmodule')
    output the JS file. I can call
    require
    manually but that doesn't seem like the right solution.
    g
    a
    • 3
    • 11
  • f

    Franco

    08/26/2020, 12:26 AM
    Hi everyone, I'm trying to use parameters from a URL (e.g.,
    /test/:id
    ) using the React Router wrapper and I can't make it work. I tried something similar to the example in the README (https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-react-router-dom/README.md) but that doesn't work as
    match
    can't be found when calling
    props.match.params.id
    . Does anyone know how to do this? This is my example:
    interface IdProps : RProps {
        var id: Int
    }
    
    class RootComponent : RComponent<RProps, RState>() {
        override fun RBuilder.render() {
            hashRouter { // or "browserRouter"
                switch {
                    route<IdProps>("/user/:id") { child(Comp2::class) {} }
                }
            }
        }
    }
    
    class Comp2 : RComponent<IdProps, RState>() {
        
        override fun RBuilder.render() {
            div {
                +"User id: ${props.match.params.id}"
            }
        }
    
    }
    • 1
    • 2
  • g

    Gunslingor

    08/26/2020, 2:18 AM
    How do yall deal with multiple levels of subcomponents, each with their own controllers, styles, view, other, etc? Specifically in relation to the controllers though. Since we are talking KJS, it seems like you have to appendChild the view AND THEN run the controller code to addEventListener too it. But that doesn't appear simple when things are nested, the lower level groups seem to fail. Does this make sense? For Example:
    class master(body: Element) {
        val master = document.create.div("d-block") { 
              childObject()
             +"MasterView" 
        )
        init {
             body.appendChild(editor)
             masterController()
        }
    }
    
    class childObject(body: Element) {
        val child= document.create.div("d-block") { 
              childObject()
             +"ChildView" 
        )
        init {
             body.appendChild(editor)
             childController()
        }
    }
    • 1
    • 2
  • m

    Mikołaj Kąkol

    08/27/2020, 8:59 AM
    hi, do you know if we can use coroutines with JS/IR in TypeScript? From what I see we cannot use
    suspend
    functions, but with
    Flow
    I've got
    d.ts
    result like:
    longAdd(a: number, b: number): kotlinx.coroutines.flow.Flow<number>;
    . Any idea if we can use it?
    a
    • 2
    • 8
  • m

    Mranders

    08/27/2020, 12:52 PM
    We're in the process of updating to the Kotlin 1.4, and are experiencing an issue. When running browserProductionWebpack, the build fails with the following error:
    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':hltv-app:browserProductionWebpack'.
    > Module 'kotlin-extensions' not found
    Module 'kotlin-react' not found
    Module 'kotlin-styled' not found
    Module 'kotlin-wrappers-kotlin-css' not found
    We have the following dependencies declared:
    implementation "org.jetbrains:kotlin-react:16.13.1-pre.111-kotlin-1.4.0"
    implementation "org.jetbrains:kotlin-react-dom:16.13.1-pre.111-kotlin-1.4.0"
    implementation "org.jetbrains:kotlin-react-router-dom:5.1.2-pre.112-kotlin-1.4.0"
    implementation "org.jetbrains:kotlin-styled:1.0.0-pre.112-kotlin-1.4.0"
    implementation "org.jetbrains:kotlin-extensions:1.0.1-pre.112-kotlin-1.4.0"
    .. And the following NPM dependencies:
    implementation(npm("react", "16.13.1"))
    implementation(npm("react-dom", "16.13.1"))
    implementation(npm("react-router-dom", "5.2.0"))
    Has anyone experienced this error, and have some way to solve it?
    i
    • 2
    • 3
  • e

    ESchouten

    08/27/2020, 2:29 PM
    When I am calling a method implemented from an interface (both default implementation or overridden in class) I get TypeError: x.x.x is not a function. Is implementing interfaces not supported yet? I am able to call other functions from that class.
    a
    • 2
    • 4
  • j

    Joost Klitsie

    08/28/2020, 8:14 AM
    Hi all! Is there an easy way to set up a proxy so NPM can download dependencies? I use a normal mutliplatform gradle project with some NPM dependencies and I have the Intellij proxy set up, as well as a proxy in my gradle.properties but I am guessing for NPM it is not enough.
    t
    • 2
    • 3
  • j

    Jorrit

    08/29/2020, 12:34 PM
    In a Gradle/Kotlin/JS project, sourceSets appears to be empty. Why is this? https://github.com/Chainfire/kotlin-js-sharedmemory/blob/master/build.gradle.kts#L52
    t
    • 2
    • 1
  • u

    3bdoelnaggar

    08/29/2020, 4:45 PM
    I got this error when I put the react router wrapper Uncaught TypeError: $receiver.child_ssazr1$ is not a function
    implementation(npm("react-router", "5.2.0"))
    implementation(npm("react-router-dom", "5.2.0"))
    implementation("org.jetbrains:kotlin-react-router-dom:5.1.2-pre.112-kotlin-1.4.0")
    t
    • 2
    • 1
  • s

    Sangeet Narayan

    08/30/2020, 5:29 AM
    Hi Everyone, I was just experimenting with Kotlin/Js and started with a full-stack template that Intellij build up for me. So far it looks interesting! Was just wondering how to use Bootstrap/ReactStrap library in my project. Can anyone help? TIA
    g
    • 2
    • 2
  • g

    Gurupad Mamadapur [FH]

    08/31/2020, 11:24 AM
    Hi, I wanted to know about error reporting tools used js applications. I've checked on sentry so far but couldn't manage to run a test crash on a mpp project(where one module targets js - browser)
    • 1
    • 1
  • d

    dazza5000

    08/31/2020, 4:33 PM
    What should I collect to debug
    e: org.jetbrains.kotlin.js.facade.exceptions.TranslationRuntimeException: Unexpected error occurred compiling the following fragment: 'package com.fivestars.integration.file.model
    • 1
    • 2
  • p

    Patrick Doering

    08/31/2020, 7:21 PM
    Hi, I try to use a npm package in a mpp project. Like from the example: dependencies {     // ...     implementation(npm("is-sorted", "1.0.5")) } @JsModule("is-sorted") @JsNonModule external fun <T> sorted(a: Array<T>): Boolean console.log("Hello, Kotlin/JS!") console.log(sorted(arrayOf(1,2,3))) console.log(sorted(arrayOf(3,1,2))) Now I wanna use another npm library with the name kafkjs in that way: dependencies {     // ...    implementation (npm( "kafkajs", "^1.12.0")) } fun createConsumer(): dynamic { return js( “kafka.consumer({groupID: ‘test-group’ })” ) } but I alwas get the error: ReferenceError: kafka is not defined Any ideas what I am doing wrong?
    t
    i
    • 3
    • 19
  • a

    agrosner

    09/01/2020, 2:17 PM
    hey all. In a Kotlin MPP I noticed when I add an
    npm
    dependency to a project running kotlin 1.4 using the new IR JS compiler, and I try to run the project, I receive an error:
    Could not determine the dependencies of task ':js-react:jsTestPackageJson'.
    > NPM Dependencies already resolved and installed
    If I remove any npm dependency, the error goes away, but seems like its something do with
    npm
    dependencies sample here: https://github.com/monstar-lab-oss/kedux/blob/master/app/build.gradle.kts uncomment any
    npm
    dependency and it wont run
    i
    • 2
    • 3
  • r

    Rob Murdock

    09/02/2020, 12:46 PM
    couldn’t find it on my own quick, so I’ll just ask - I’m having trouble using a suspend main function when running karma tests. Is this a known issue, unique to me, or anyone got a fix? (the test run fails, timing out after never receiving a signal)
    t
    • 2
    • 6
  • b

    bill1550

    09/02/2020, 5:30 PM
    Any suggestions would be greatly appreciated.
    t
    i
    • 3
    • 7
  • d

    dazza5000

    09/03/2020, 2:22 PM
    i think you can import the standard lib through npm
    f
    • 2
    • 4
Powered by Linen
Title
d

dazza5000

09/03/2020, 2:22 PM
i think you can import the standard lib through npm
f

ftomassetti

09/03/2020, 3:47 PM
thank you Darran! Do you know how? I tried with
npm i kotlin
but I still get the same error
d

dazza5000

09/03/2020, 7:28 PM
i dont know how
i did it naively initially by copying a file called kotlin.js to the project
I'm not an expert - maybe someone else knows exactly what to do
View count: 4