https://kotlinlang.org logo
#javascript
Title
# javascript
a

Ashley Arthur

08/03/2022, 11:04 AM
Hi all, another KMP -> JS question if anyone knows: When compiling a Kotlin method with default values, it seems the current behaviour ( 1.7.10 ) is to make ALL parameters in the function signature ‘optional’ in terms of the Typescript definition, even the ones where we haven’t specified a default value. Is this by design? It seems unsafe, because the params without defaults will possibly be undefined when the function is called from JS. example code: Kotlin
Copy code
fun hello(param1:String, param2:String, param3:Boolean = false ) {}
JS.dt.ts
Copy code
hello(param1?: string, param2?: string, param3?: boolean): void;
b

Big Chungus

08/03/2022, 11:28 AM
Smells like a bug for youtrack
Which is expected seeing as d.ts generation is still experimental
a

andylamax

08/03/2022, 1:57 PM
I have noticed this as well, is there a ticket I can follow??
s

shaktiman_droid

08/27/2022, 6:05 PM
In
1.6.20
, default value support was broken for Typescript, so looks like they tried to fix it in
1.7.x
but now if you’ve one param with default value then all becomes optional. if you remove the default value from boolean above, then it works fine on
1.7.10
. So yeah definitely a bug at this point!
4 Views