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
  • m

    Martin Gaens

    04/22/2022, 7:55 AM
    Hey everyone! I'm getting very unexpected behavior from Kotlin/JS and I have no idea what is happening and why it is happening. Basically, I have code that gets me a
    List
    of `HTMLDivElement`s:
    val questionDivs = document.querySelectorAll("div[id^='question']").asList().map { it as HTMLDivElement }
    Then, if I print it out to the console, by using
    console.log(questionDivs)
    , it prints out just fine. If I print out the size of this
    List
    , by using
    console.log(questionDivs.size)
    , it prints out the size of the
    List
    (in my case 11). But if I try to loop over the
    List
    by using either a foreach loop or by using the
    .forEach { }
    method, it isn't being run not even once. This is what gets printed out when doing `console.log(questionDivs)`: https://paste.pics/GR0JS
    :blob-shrug: 2
    g
    • 2
    • 3
  • m

    Martin Gaens

    04/22/2022, 4:50 PM
    And this doesn't?
    r
    e
    • 3
    • 17
  • m

    mike.holler

    04/22/2022, 9:23 PM
    Okay, one more. Is there a way to reference a JavaScript
    Number
    type in Kotlin?
    Number
    is
    kotlin.Number
    , which is not what I want. Is there a
    javascript.Number
    or something?
    t
    e
    • 3
    • 76
  • b

    Benjamin Charais

    04/23/2022, 11:31 PM
    Hi all! Hope everyone is well. I'm currently working in a multiplatform project where I have an NPM dependency. I've been trying to figure out how to compile the dependency into my output so that it isn't necessary for a consumer to resolve the dependency. We have a multiplatform module, (core), and a kotlin/js standalone that will be used as an SDK, the JS module depends on the core. Currently any consumer must have the package installed via NPM in some way. Is this out of the box possible, or is anyone aware of work around?
    t
    • 2
    • 40
  • a

    Akram Bensalem

    04/24/2022, 12:12 PM
    Hello! How to fix this issue? When use short url like "/" or "/somthing" it works fine because it return the index.html that has the script of WebApp.js But when using long url like "/somthing/sothingelse" I got this error It can't serve the index.html Any idea how to fix it ?
    r
    • 2
    • 2
  • g

    gabin

    04/24/2022, 1:45 PM
    Hi. I was trying to use ktor js client and failed to load anything because of CORS policy. How can it be handled ?
    b
    • 2
    • 9
  • m

    mike.holler

    04/25/2022, 8:24 PM
    I found this post from 2 years ago. Is it still following best practice, or has another method been created since then?
    ➕ 1
    e
    • 2
    • 3
  • k

    Konyaco

    04/26/2022, 10:45 AM
    Hi😃, I'm trying to use minecraft script framework in kotlin, but I meet some problems in converting TS definition to kt. Here are dependencies:
    implementation(npm("@types/mojang-gametest", "^0.1.3", generateExternals = true))
    implementation(npm("@types/mojang-minecraft", "^0.1.3", generateExternals = true))
    implementation(npm("typescript", "^4.4.3"))
    implementation(npm("gulp", "^4.0.2"))
    implementation(npm("gulp-typescript", "^6.0.0-alpha.1", generateExternals = true))
    implementation(npm("del", "^6.0.0"))
    Problem 1 Here are excerpts from
    @types/mojang-minecraft
    dependency:
    export class MinecraftItemTypes {
        static readonly 'air': ItemType;
        static readonly 'apple': ItemType;
    //  ...
        static readonly 'item.acaciaDoor': ItemType;
        static readonly 'item.bed': ItemType;
    }
    There are some fields which have a
    .
    in their name. And they are converted to:
    external open class MinecraftItemTypes {
        companion object {
            var item.acaciaDoor: ItemType
            var item.bed: ItemType
            var item.beetroot: ItemType
        }
    }
    They can not be compiled, should they be converted like this?
    var `item.acaciaDoor`: ItemType
    Also, the TS uses
    readonly
    keyword, I'm not familiar with TypeScript, may be it should be converted to
    val
    ? Problem 2 There are some fields, store a literal value:
    export class BlockProperties {
        static readonly 'active' = 'active';
        static readonly 'color' = 'color';
        static readonly 'direction' = 'direction';
        // ...
    }
    They are converted to:
    external open class BlockProperties {
        companion object {
            var active: Any = "active"
            var color: Any = "color"
            var direction: Any = "direction"
        }
    }
    They are reported wrong with
    Wrong initializer of external declaration. Must be ' = definedExternally'
    In addition, is it possible to infer the type
    String
    ?
    val active: String = definedExternally
    Are these bugs? How can I deal with them?🤔
    t
    e
    • 3
    • 6
  • h

    hfhbd

    04/27/2022, 1:14 PM
    Hey, I have a compose web library (bootstrap-compose) which uses the npm library bootstrap. This dependency contains the released css and js files, which I want to forward them to my consumers, via
    api(npm("bootstrap"))
    . The js files are included, but the css files are not. How can I publish the css files too, so the user does not need to import it separatly?
    b
    • 2
    • 18
  • w

    Wyatt Kennedy

    04/28/2022, 9:21 PM
    Hi, I want to use the html-loader module in webpack to load an html file into a string constant. I added a webpack.config.d directory to the root of my kotlin js project and confirmed that the js file in there was included in the generated webpack.config.js in {projectRoot}/build/js/packages/{projectName} on browserDevelopmentRun . From here, I am not sure where to put my html files or how I should configure webpack to find the html files in the src directory of my kotlin project. Does anyone have any experience with this?
    t
    • 2
    • 8
  • d

    David Gonzalez

    04/28/2022, 9:49 PM
    Hey, • I have a multi platform project • one of the modules is a JS module, which is going to be exported • that module uses objects from the other modules, added as dependencies When I export the JS file, I can export the classes in the JS module, but not the classes in the other modules, Is there a way to make webpack to export them?
    t
    a
    • 3
    • 6
  • g

    GoldenCow

    04/29/2022, 5:21 AM
    Hello. I was wondering what would be the benefits of building a web app with Kotlin Multiplatform, instead of mixing JS and Kotlin separately. I want to get an idea of in which situations would using Kotlin Multiplatform be more beneficial than mixing those two.
    r
    g
    +2
    • 5
    • 4
  • w

    Wyatt Kennedy

    04/30/2022, 8:36 AM
    Is there a way to force the project to include a module even if I don't reference it at all? I currently have to kind of hack it like so:
    @JsModule("reflect-metadata")
    external val blank : dynamic
    val force = blank.test
    I just want the module to be included and run always. Without something like this being in the code somewhere, it never gets run and other dependencies that require it fail on load. putting the
    package.to.blank
    in the dce keep option does not retain it. Did I miss anything in the documentation?
    t
    • 2
    • 2
  • p

    Pavel Matusevich

    05/02/2022, 12:24 AM
    Hello everyone! I am making Kotlin definitions for a JS library using type definitions from Typescript and I've encountered this syntax: (typescript)
    _showAuthDialog({ nonInteractive, error, canCancel, onTryAgain }?: AuthDialogParams): void;
    What would be the best way to write Kotlin definition for that function? Just to replace argument name with any valid string or..? Just in case, AuthDialogParams definition:
    interface AuthDialogParams {
        nonInteractive?: boolean;
        error?: Error;
        canCancel?: boolean;
        onTryAgain?: () => Promise<void>;
    }
    Thanks in advance!
    n
    • 2
    • 1
  • a

    Alexander Stoppel

    05/03/2022, 7:00 AM
    Hi all, How do I call a Kotlin-Function from JavaScript when the
    @JsExport
    -annotated function is located in a different module? Within the same module, I would use
    js("myModule.myFuntion();")
    which works fine but calling
    js("myOtherModule.myOtherFunction();")
    fails since JavaScript fails to resolve
    myOtherModule
    Is there a Gradle configuration or anything else I can do to access
    myOtherModule
    from JS when running
    myModule
    ?
    g
    • 2
    • 4
  • t

    thana

    05/03/2022, 7:56 AM
    Hi, 2 weeks ago
    kotlin-react-css
    was removed from the wrappers project (https://github.com/JetBrains/kotlin-wrappers/pull/1450) does anyone know why?
    l
    t
    • 3
    • 5
  • t

    thana

    05/03/2022, 7:59 AM
    though my actual question is: i was reading https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/01_Introduction to get my feet wet with kotlin and react. now it still uses react 17 and makes use of kotlin-react-csss taht is now removed. how would i handle css with react 18?
    t
    • 2
    • 3
  • t

    tylerwilson

    05/03/2022, 1:28 PM
    I am curious if anybody has an example of a React Native project, but using Kotlin instead of JS/TS?
    b
    r
    • 3
    • 3
  • t

    thana

    05/03/2022, 6:53 PM
    is there a howto guide or something similar about how to use a js library when there are no kotlin wrappers? i want to use d3.js and im kinda lost. I managed to geenrate the external declarations but of all the thigns its the d3-object itself that has no interface or something... also im unsure about how to use the genersated external during development
    r
    • 2
    • 2
  • w

    willyrs

    05/03/2022, 7:27 PM
    Hello, I have a problem with minification.. I have a project generating a js library that I use from a reactJS app, and I've noticed that jsBrowserDevelopmentWebpack and jsBrowserProductionWebpack produce the same, not minified, files. Should I do something to activate minification in production? I tried to create the webpack.config.d folder but I have an error saying webpack is not defined at this line:
    config.plugins.push(new webpack.optimize.UglifyJsPlugin({
      minimize: true
    }));
    EDIT: I've added
    const webpack = require('webpack');
    and now the error is [webpack-cli] TypeError: webpack.optimize.UglifyJsPlugin is not a constructor
    t
    • 2
    • 1
  • t

    thana

    05/04/2022, 11:50 AM
    Hello again 🙂 some of the examples from https://mui.com/material-ui/react-drawer/ only work, because they directly manipulate some of the css classes like so:
    <Drawer
            sx={{
              width: drawerWidth,
              flexShrink: 0,
              '& .MuiDrawer-paper': {
                width: drawerWidth,
                boxSizing: 'border-box',
              },
            }}
    How would i add these stylings to the MuiDrawer-paper class the kotlin way?
    t
    • 2
    • 5
  • b

    bashor

    05/05/2022, 2:44 PM
    https://twitter.com/bashorov/status/1522225395008946176
    👍🏽 1
    👍🏾 1
    🎉 6
    🤯 3
    ❤️ 5
    👍 3
    👍🏻 1
    a
    b
    m
    • 4
    • 3
  • r

    rrva

    05/05/2022, 3:42 PM
    If i am writing a multiplatform lib targeting android, ios and js, what is a good solution for multiplatform caching for example the LoadingCache pattern Lets say i have a
    suspend fun refreshToken(token: Token)
    if the cache is cold, I want to prevent to coroutines concurrently refreshing the value I have tried some solutions Semaphore (the coroutine aware one) Actor-like impl with channels but without actor lib. Are there any other simpler/more obvious solutions?
    a
    • 2
    • 4
  • d

    Derek Ellis

    05/06/2022, 1:57 PM
    If I'm making a Kotlin/JS library that needs to have a web worker component to it, is there any simple way to ship the library so that the main js compilation and the web worker script are both available to library consumers in some way?
    b
    t
    a
    • 4
    • 3
  • m

    mike.holler

    05/06/2022, 4:55 PM
    Anyone know if there's a bug for this? I'm still seeing promises as non-exportable in 1.6.21.
    h
    • 2
    • 16
  • a

    Ayfri

    05/06/2022, 7:51 PM
    Hi, is it possible to see the JS generated before adding kotlin stdlib and optimizing the code (or even before bundling the files) ?
    j
    • 2
    • 1
  • j

    Jonathan Ellis

    05/06/2022, 9:27 PM
    what would i need to do to a kotlin/js build.gradle.kts to also allow running on the jvm as a desktop app?
    a
    r
    • 3
    • 10
  • a

    Ayfri

    05/07/2022, 2:06 PM
    Why is it the case ? Is it planned to fix it ?
    • 1
    • 1
  • t

    thana

    05/08/2022, 5:14 PM
    i want to use a material ui textfield with InputAdorments. in the mui docs it is decalred like so
    InputProps={{
                startAdornment: <InputAdornment position="start">kg</InputAdornment>,
              }}
    How do i do that in kotlinjs? i cant find any implementation of
    InputBaseComponentProps
    t
    a
    • 3
    • 17
  • e

    Eryk Lepszy

    05/08/2022, 11:02 PM
    Are there any examples on how to use DatePickers from kotlin material ui wrapper? I'm not sure how can I pass any additional props that are not defined in external interface that is used in them, such as inputFormat or onChange handler.
    l
    t
    • 3
    • 3
Powered by Linen
Title
e

Eryk Lepszy

05/08/2022, 11:02 PM
Are there any examples on how to use DatePickers from kotlin material ui wrapper? I'm not sure how can I pass any additional props that are not defined in external interface that is used in them, such as inputFormat or onChange handler.
l

Luc Girardin

05/09/2022, 8:47 AM
You can fallback on asDynamic(), e.g.
asDynamic().inputFormat = "dd.MM.yyyy HH:mm"
t

turansky

05/09/2022, 12:05 PM
Temp workaround (preferred)
var DatePickerProps.inputFormat: String
    get() = asDynamic().inputFormat
    set(value) { asDynamic().inputFormat = value }
Say NO to
asDynamic()
!
And issue
View count: 3