Edoardo Luppi
05/05/2026, 3:21 PM@JsExport on initHook?
https://github.com/ktorio/ktor/blob/3e70e934088aebbd0827ebba5b5d68a17c62ab1f/ktor-client/ktor-client-cio/js/src/io/ktor/client/engine/cio/Loader.js.kt#L14Edoardo Luppi
05/05/2026, 3:23 PMOleg Yukhnevich
05/05/2026, 3:25 PM@JsExport makes it usable in an exported JS module, and so the initializer is called - otherwise, as it's not "exported" and it's not called anywhere it's just removed by DCEOleg Yukhnevich
05/05/2026, 3:26 PMEdoardo Luppi
05/05/2026, 3:34 PMinitHook in the generated d.ts.
From my quick testing, it looks like @EagerInitialization now also works on unused properties.Edoardo Luppi
05/05/2026, 3:34 PMOleg Yukhnevich
05/05/2026, 3:41 PMFrom my quick testing, it looks likeyes! it really works! I've checked on Kotlin 2.3.20 - works for both default andnow also works on unused properties.@EagerInitialization
es2015 JS target
So, looks like it might have been fixed at some pointEdoardo Luppi
05/05/2026, 3:42 PMBruce Hamilton
05/06/2026, 6:55 AM@JsExport now? very niceOleg Yukhnevich
05/06/2026, 7:26 AMEdoardo Luppi
05/06/2026, 7:28 AMEdoardo Luppi
07/16/2026, 8:37 AM@OptIn(ExperimentalStdlibApi::class)
@EagerInitialization
@JsName("example")
private val example = run {
js("eval('void example')")
return@run "value without side-effects"
}
Webpack will see void example and back off from removing it.Edoardo Luppi
07/16/2026, 8:42 AMeval is required because js literals are parsed and contribute to variable name uniqueness checks. If you use js("void example") the example variable will never exist.