Any idea where js.core.JsNumber has gone? I need a...
# javascript
b
Any idea where js.core.JsNumber has gone? I need a class reference to that (JsNumber::class.js). Removing the import uses a double which does not exist in my browser
✅ 1
image.png
t
Which wrappers version do you use?
Strict common number types are here. They are for type parameters only.
b
upgraded from 2026.3.3 to 2026.3.15 I think
I need the equivalent of Number in JS
IIRC Number::class.js wasn't working back then
let me check
yep, that exports to Number_0
t
kotlin.js.JsNumber
b
that produces Uncaught (in promise) ReferenceError: Double is not defined
t
Non-aligned dependencies?
b
Copy code
[versions]
kotlin = "2.3.20"
coroutines = "1.10.2"
schema-validator = "0.5.4"
ktor = "2.3.12"
serialization = "1.10.0"

[libraries]
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.7.1" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html-js", version = "0.12.0" }
kotlin-wrappers = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom", version = "2026.3.15" }
kotlin-plain-objects = { module = "org.jetbrains.kotlin:kotlin-js-plain-objects", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-wrappers-js = { module = "org.jetbrains.kotlin-wrappers:kotlin-js" }
kotlin-wrappers-web = { module = "org.jetbrains.kotlin-wrappers:kotlin-web" }
kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js-runner", version = "2.0.21" }
kotlinx-coroutines-js = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js", version.ref = "coroutines" }
jsonschemavalidator = { module = "io.github.optimumcode:json-schema-validator", version.ref = "schema-validator" }
jsonschemavalidator-js = { module = "io.github.optimumcode:json-schema-validator-js", version.ref = "schema-validator" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
logback = { module = "ch.qos.logback:logback-classic", version = "1.5.8" }
jsoup = { module = "org.jsoup:jsoup", version = "1.19.1" }

[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-plain-objects = { id = "org.jetbrains.kotlin.plugin.js-plain-objects", version.ref = "kotlin" }
versions = { id = "com.github.ben-manes.versions", version = "0.53.0" }
download = { id = "de.undercouch.download", version = "5.7.0" }
dependencyUpdates task shows no later version at least
t
Very old Ktor?
b
same issue with 3.4.1
t
Caches problem?
b
are there more caches than in build/
t
js.core.JsNumber
was removed, because it was required as namespace only
What is your use case?
b
I need to pass a class to a JS API
it's a settings API that requires a reference of Number, String, Date or a specific class
t
Kotlin/JS?
b
something like:
Copy code
settings.register('key', {type: Number, default: 0})
t
Kotlin/JS?
b
yes
t
Double::class.js
?
b
that gives me
Copy code
Uncaught (in promise) ReferenceError: Double is not defined
    registerInt Pfrpg2eKingdomCampingWeatherSettings.kt:63
    t3q Pfrpg2eKingdomCampingWeatherSettings.kt:316
    s3q Main.kt:93
    xb GeneratorCoroutineImpl.kt:31
    rb GeneratorCoroutineImpl.kt:59
    sb main.js:76297
    o15 Continuation.kt:45
    b1b JSDispatcher.kt:127
    lambda JSDispatcher.kt:55
    promise callback*c1b JSDispatcher.kt:55
    f1b JSDispatcher.kt:118
    y15 JSDispatcher.kt:56
    safeDispatch DispatchedContinuation.kt:254
    dispatch DispatchedTask.kt:145
    dispatchResume CancellableContinuationImpl.kt:470
    h15 CancellableContinuationImpl.kt:504
    g15 main.js:90699
    sb CancellableContinuationImpl.kt:359
    lambda Continuation.kt:45
    promise callback*./kotlin/kotlinx-coroutines-core.mjs/await_0/< Promise.kt:64
    xb GeneratorCoroutineImpl.kt:40
    rb GeneratorCoroutineImpl.kt:59
    sb main.js:76297
    o15 Continuation.kt:45
    b1b JSDispatcher.kt:127
    lambda JSDispatcher.kt:55
    promise callback*c1b JSDispatcher.kt:55
    f1b JSDispatcher.kt:118
    y15 JSDispatcher.kt:56
    safeDispatch DispatchedContinuation.kt:254
    resumeCancellableWith DispatchedContinuation.kt:211
    startCoroutineCancellable_0 Cancellable.kt:26
    s10 CoroutineStart.kt:358
    p10 AbstractCoroutine.kt:134
    async Builders.common.kt:88
    promise Promise.kt:26
    buildPromise Lang.kt:39
    lambda Main.kt:91
    #call foundry.mjs:23832
    callAll foundry.mjs:23791
    initialize foundry.mjs:167566
    initialize foundry.mjs:169017
    <anonymous> foundry.mjs:181096
    async*
console.log(Double::class.js)
t
Copy code
package js.numbers

@JsName("Number")
val NumberClass: JsClass<JsNumber>
PR? 😉
b
will do after work 🙂
looking into it, there's
Copy code
@JsName("Number")
private external class JsNumber :
    Localizable<NumberFormatOptions> {

    constructor(value: Int)
    constructor(value: Double)

    fun toExponential(fractionDigits: Int = definedExternally): String
    fun toFixed(digits: Int = definedExternally): String
    fun toPrecision(precision: Int = definedExternally): String
}
the issue here is that it's private
I've added
Copy code
@JsName("Number")
external class JsNumber
in my project and got it working, so looks to me like I'd just remove the private modifier?
t
As you described - you need
JsClass
only, right?
b
Copy code
@JsName("Number")
val NumberClass: JsClass<JsNumber>
needs to be initialized
t
external ;)
b
tried that as well
not a subtype of JsAny 🙂
and a warning about exposing a private type
t
On compile time?
Don't use private type ;)
b
e: file///home/bernhard/dev/kotlin wrappers/kotlin js/src/webMain/kotlin/js/numbers/JsNumber.kt26:14 'public' property exposes its 'private-in-file' type argument 'JsNumber'.
t
Use standard
JsNumber
b
ah I see
Copy code
@JsName("Number")
external val NumberClass: JsClass<kotlin.js.JsNumber>
I guess
is there a reason for hiding the external class for Number?
to not conflict with kotlin.js.JsNumber and just add a couple additional things?
tbh maybe JsNumber::class.js from the base js lib itself should point to the correct platform type
maybe the best way forward is to not create a PR but to discuss this in the Kotlin issue tracker
t
tbh maybe JsNumber::class.js from the base js lib itself should point to the correct platform type
It's alias of
Double
😉
maybe the best way forward is to not create a PR but to discuss this in the Kotlin issue tracker
@Artem Kobzar is there any reason why
Double::class.js
call fails/doesn't return
Number
?
@Bernhard probably issue is already exists. If yes - please share it.
b
https://youtrack.jetbrains.com/issue/KT-22156/Creating-a-class-inherited-from-Number-results-in-the-generation-of-inoperative-JavaScript-code is sort of related but I can't find anything else; I'll probably create a reproducible piece of code and create an issue later this evening
t
Oh, inheritance case is real 😉
a
Oh, sorry, @Bernhard for the late reply. I've dove into the case and it's a bug inside of the compiler optimization (I will fix it in 2.4.0). As a workaround, try to do the following:
Copy code
val kClass = Double::class

kClass.js // Should be Number
❤️ 1
b
thank you so much
a
Thank you for reporting it 🙏