https://kotlinlang.org logo
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
  • h

    hfhbd

    08/16/2021, 9:59 AM
    I don't get it, why the error
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
    happens with my
    runTest
    implementation using JS IR:
    val testScope = MainScope()
    fun runTest(block: suspend CoroutineScope.() -> Unit): dynamic = testScope.promise { block() }
    p
    r
    • 3
    • 7
  • p

    Pitel

    08/16/2021, 12:47 PM
    I have an interop problem. https://github.com/codemirror/CodeMirror/blob/master/addon/mode/simple.js#L69 this code, if I'm using the Kotlin's
    Regex
    object, it doesn not match. Is there some workaround?
    t
    • 2
    • 1
  • d

    Didier Villevalois

    08/16/2021, 12:58 PM
    Hi all! I'm trying to generate externals for
    zeromq.js
    with
    implementation(npm("zeromq", "6.0.0-beta.6", generateExternals = true))
    but I get some problems with the generated KT sources. Apart from some problems with some type parameters,
    Buffer
    (a node class) seems to not being correctly linked to Node declarations. Namely, I get a:
    Unresolved reference: Buffer
    Is there something I am not doing right? Or is there a workaround for this, or a simple PR that I could contribute to Dukat?
    p
    a
    t
    • 4
    • 5
  • c

    CLOVIS

    08/16/2021, 2:54 PM
    I just got this error message when running a React app:
    [webpack-cli] Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
    - configuration has an unknown property '_assetEmittingWrittenFiles'. These properties are valid:
    object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, public?, setupExitSignals?, static?, transportMode?, watchFiles? }
    I don't know where this comes from. I can't even run the code from a week ago, which is definitely correct.
    ☝️ 1
    t
    • 2
    • 2
  • r

    Robert Jaros

    08/16/2021, 3:07 PM
    This is what happens when you use beta versions in production 😉
    t
    • 2
    • 1
  • d

    Didier Villevalois

    08/16/2021, 3:56 PM
    Any hints as to how to convert a Node
    Buffer
    to a Kotlin
    ByteArray
    , and vice-versa ?
    👀 1
    t
    • 2
    • 5
  • d

    Didier Villevalois

    08/16/2021, 11:49 PM
    How can I run a test with coroutines in Kotlin/JS ? Currently, I am using
    GlobalScope.launch
    because there is no
    runBlocking
    in Kotlin/JS. However, assertion errors are not correctly collected and the test doesn't fail when an assertion fails.
    @Test
    fun testSimple() = GlobalScope.launch {
        // ...
    }
    • 1
    • 2
  • r

    Rahim Klaber

    08/17/2021, 1:06 AM
    Hi, does someone know how to disable hostcheck for the webpack devserver(https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)? I tried adding
    config.devServer.disableHostCheck=true
    in a webpack config snippet, but It tells me that disableHostCheck is not a valid property. I don't have much experience with webpack but from what I understand what I did should work.
    t
    • 2
    • 2
  • k

    kk57

    08/17/2021, 9:43 AM
    Hi everyone, has anyone tried dukat for generating equivalent kotlin wrapper with “react-json-view” lib? implementation(npm(“react-json-view”, “^1.21.3”,generateExternals = true)) throws 500+ errors for me 😓
    😔 1
    t
    • 2
    • 4
  • c

    CLOVIS

    08/17/2021, 4:08 PM
    Hi, I have a Kotlin
    ByteArray
    that contains the binary data of an image (
    image/png
    ). I'm trying to display that image to the user. So far I have:
    val blob = Blob(arrayOf(data), BlobPropertyBag(
        type = "image/png",
    ))
    val url = URL.createObjectURL(blob)
    window.open(url, target = "_blank", features = "noopener,noreferrer")
    However, running the code opens a tab with a small grey square, no matter the original image. I think the blob conversion is the culprit, but I'm honestly not sure. Because
    Blob
    takes an
    Array<dynamic>
    , I have no meaningful way of knowing what's wrong with it.
    t
    • 2
    • 3
  • t

    Tianyu Zhu

    08/17/2021, 9:31 PM
    I'm getting a strange error in the Kotlin JS/IR compiler. Can anyone help me decode this stacktrace?
    Compiler Error.txt
    t
    r
    • 3
    • 5
  • a

    altavir

    08/18/2021, 7:52 AM
    I've suddenly started to get
    > [webpack-cli] Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
       - configuration has an unknown property '_assetEmittingPreviousFiles'. These properties are valid:
         object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, public?, setupExitSignals?, static?, transportMode?, watchFiles? }
    error in webpack run tasks. I am not sure what changed. Does anybody else have the promblem?
    a
    r
    m
    • 4
    • 10
  • m

    Marius Ailinca

    08/18/2021, 8:17 AM
    Hi! Newbie alert! 🙂 . I am trying to fix some dukat issues. Do you know how I can transpile this (index.d.ts) to kotlin: _*enum* State {                                                                  _    ERROR = -1.0 ,                                                                  LOADING = 0.0 ,                                                                 READY = 2.0 ,                                                                   VISIT = 1.0 ,                                                                _ *}*_
    t
    • 2
    • 2
  • m

    Marius Ailinca

    08/18/2021, 8:24 AM
    Another question: I am trying to integrate with Here Maps which they have a js bundle ("https://js.api.here.com/v3/3.1/mapsjs.bundle.js"). It doesn't have a module name in the bundle. Is there an example on how I can include third-party scripts and use them in kotlin js? I read the documentation but my JS knowledge is quite limited. Thanks and congrats for the great work! 😉
    a
    • 2
    • 7
  • c

    CLOVIS

    08/18/2021, 9:36 AM
    To my knowledge, the Gradle plugin installs Node somewhere so it can use it with Yarn & everything. Is there a way to create a custom Gradle task that uses that node installation? I only found plugins that maintain a second node installation, but that's sub-optimal. Essentially, I have a
    devNpm
    dependency that has a JS script I'd like to run during development. So far I've done it by using my locally installed /usr/bin/node, but that's not portable (especially for CI); I'd like to take advantage of Kotlin's Node installation.
    e
    j
    • 3
    • 11
  • c

    CLOVIS

    08/18/2021, 11:02 AM
    In case anyone is interested, here's how I removed ~600kB from my JS file using the Google Closure Compiler: https://stackoverflow.com/questions/68831061/how-to-use-the-google-closure-compiler-to-optimize-kotlin-js/68831062#68831062
    🆒 3
    :nice: 1
    r
    e
    +2
    • 5
    • 14
  • b

    bsimmons

    08/18/2021, 11:51 AM
    Hey all, I am getting a "doubled" promises in some of my code and I end up manually casting. Is there a way to avoid this anti-pattern?
    /** Convert promise with HTTP 500 response to failed promise. */
    fun Promise<Response>.handleErrorCodes(): Promise<Response> = then { response ->
        if(response.ok) response
        else response.text().then { body ->
            throw RuntimeException("${response.status}: $body")
        }
    }.then { it as Response }
    t
    t
    • 3
    • 4
  • k

    kpgalligan

    08/18/2021, 3:57 PM
    Hi all! I've been doing some research into Kotlin/JS use in production and am looking for any good info on JS output size. I know this is a "it depends" kind of question, but if anybody has links to posts or discussions on the topic, that would be much appreciated. (I can trade for good info on Kotlin-iOS binary size 🙂 )
    👀 2
    t
    b
    • 3
    • 11
  • m

    Marius Ailinca

    08/19/2021, 8:29 AM
    Hi! Any idea how I can write this js in Kotlin? :
    var map = new H.Map(
    {
    center: {lat: 40.745390, lng: -74.022917},
    zoom: 13.2
    });
    center is not properly initialized. I tried defining an interface for center (IPoint) and pass an object:IPoint to the constructor but it doesn't work. Tried to implement the interface in a class and still doesn't work. How to I pass a json anonymous object from kotlin to js? Thank you!
    h
    t
    • 3
    • 5
  • n

    Nikolai Sviridov

    08/19/2021, 6:36 PM
    Hello! How can I add files (such as .png, .obj (3d model)) in webpack and use their paths in code? As reference, I use this project without any changes to config. In local experiments, I start a local server and get files by paths ""

    http://127.0.0.1:5500/my_file.png▾

    ". Is there a similar way?
    t
    • 2
    • 6
  • a

    allanhasegawa

    08/20/2021, 1:01 PM
    Hey o/ I'm wondering if it would be possible to migrate an existing JS Node project to KotlinJS in small chunks, where both JS and KotlinJS exists in the same codebase for a while. Would this be doable? Does anyone know of any material (article, blog posts, etc) that could help me here?
    b
    • 2
    • 1
  • d

    Dra

    08/21/2021, 5:35 PM
    Hi! How do you do testing when you require an element from the document? For more details : I am testing a method that requires a value modified in the HTML of the page so I have created a getter that looks like this :
    val prompt get() = document.querySelector(".prompt-box")!!
    When I run the page "normally" it works I can use the things how I want but when I try to run my test I always get this stacktrace :
    NullPointerException
    	at Object.captureStack(/tmp/_karma_webpack_318847/commons.js:40068)
    	at NullPointerException.constructor(/tmp/_karma_webpack_318847/commons.js:40401)
    	at NullPointerException.constructor(/tmp/_karma_webpack_318847/commons.js:40427)
    	at RuntimeException.init(/tmp/_karma_webpack_318847/commons.js:40438)
    	at <global>.new NullPointerException(/tmp/_karma_webpack_318847/commons.js:40547)
    	at Object.throwNPE(/tmp/_karma_webpack_318847/commons.js:44251)
    	at Kotlin.ensureNotNull(/tmp/_karma_webpack_318847/commons.js:2224)
    	at Object.get_prompt(/tmp/_karma_webpack_318847/commons.js:66566)
    	at TestClient.testAddCharToOperation(/tmp/_karma_webpack_318847/commons.js:66475)
    	at <global>.<unknown>(/tmp/_karma_webpack_318847/commons.js:66523)
    (The div with a class exists in my HTML) I tried out some things but I couldn't manage to make the tests work properly... Here's my last try :
    @Test
        fun testAddCharToOperation() {
            val div = document.createElement("div")
            div.innerHTML = """<div class="prompt-box">0</div> """
    
            assertEquals("", operation)
            assertEquals("0", prompt.textContent)
    
            addCharToOperations('1')
            assertEquals("1", operation)
            assertEquals("1", prompt.textContent)
    }
    b
    a
    • 3
    • 9
  • t

    Tuna

    08/22/2021, 5:44 AM
    Hi! I want to use SASS in my project (Kotlin JS) but not sure how to config the gradle for compiling SASS -> CSS. Currently, I have to run
    sass
    to compile.
    r
    • 2
    • 2
  • n

    Nikola Milovic

    08/23/2021, 9:52 AM
    What is the usual process of turning a regular html element into a React Element 1) I can apply classes in the css and in the attrs section, where do they go (in the example below)? 2) Can I slap them all in a single string like in html? Or do I have to create a mutable list every time? (class("btn-close text-reset") or class = mutableListOf("","") 3) How do I add custom attributes? ("data-bs-dismiss" in the example)
    <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
    Using this as an example, as it has all of the above questions. Classes are from bootstrap
    t
    • 2
    • 1
  • p

    Pitel

    08/23/2021, 12:19 PM
    val sortDom = document.querySelector("thead th span") as SPAN
    sortDom.click() // Why is there no click() method?! It works in browser.
    b
    t
    • 3
    • 3
  • v

    vonox7

    08/23/2021, 5:08 PM
    Any idea how to check if a
    T
    is an Enum? I’m really afraid to write code like
    T::class.js.toString().contains("Enum.call(this")
    , although this works for the legacy compiler (
    Enum.call(this);
    ) and for the IR compiler (
    Enum.call(this, name, ordinal);
    ) Question on StackOverflow
    t
    a
    e
    • 4
    • 13
  • a

    Ayfri

    08/23/2021, 7:56 PM
    Hi, if I mark a file as
    @file:JsModule
    , how can I declare an non-external interface (an external function return an object without external interface so I created a local interface) ?
    t
    • 2
    • 10
  • a

    Ayfri

    08/23/2021, 9:46 PM
    How can I transcript in Kotlin a TypeScript interface that extends a class ?
    t
    b
    • 3
    • 5
  • p

    Pitel

    08/24/2021, 9:24 AM
    Has someone successfully integrated with Redux Dev Tools? I'm trying to do this, but it breaks my app.
    createStore(
        reducers,
        jsObject(),
        compose(
            rEnhancer()
        ) {
            if (window.asDynamic().__REDUX_DEVTOOLS_EXTENSION__) {
                window.asDynamic().__REDUX_DEVTOOLS_EXTENSION__()
            } else {
                it
            }
        }
    )
    b
    r
    • 3
    • 7
  • a

    Ayfri

    08/24/2021, 10:26 PM
    Hi, what would be the Kotlin equivalent of this :
    export class A<T extends (...args: any[]) => void> {
    
    }
    
    type B = (a: string, b: string, c: string) => void;
    
    export interface C {
        foo: A<B>
    }
    I tried this but it says
    Type argument is not within its bounds.
    :
    open external class A<T : (args: Array<out Any>) -> Unit)
    
    typealias B = (a: String, b: String, c: String) -> Unit
    
    external interface C {
        var foo: A<B>
    }
    t
    • 2
    • 4
Powered by Linen
Title
a

Ayfri

08/24/2021, 10:26 PM
Hi, what would be the Kotlin equivalent of this :
export class A<T extends (...args: any[]) => void> {

}

type B = (a: string, b: string, c: string) => void;

export interface C {
    foo: A<B>
}
I tried this but it says
Type argument is not within its bounds.
:
open external class A<T : (args: Array<out Any>) -> Unit)

typealias B = (a: String, b: String, c: String) -> Unit

external interface C {
    var foo: A<B>
}
t

turansky

08/24/2021, 11:02 PM
T: Function<Unit>
a

Ayfri

08/24/2021, 11:04 PM
wow it was so simple, thanks !
t

turansky

08/25/2021, 2:22 AM
Works?
a

Ayfri

08/25/2021, 2:22 AM
yes !
View count: 11