I'm trying the `Dukat` in order to allow the autom...
# javascript
f
I'm trying the
Dukat
in order to allow the automatic conversion of TypeScript declaration files and I'm having some issues. I will post in the thread!
👀 1
I enabled the following flag in my project:
Copy code
kotlin.js.experimental.generateKotlinExternals=true
And here is the output of `Dukat`:
Copy code
@file:JsModule("mock-socket")
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")
package mock_socket

import kotlin.js.*
import kotlin.js.Json
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*

external open class EventTarget {
    open var listeners: Any
    open fun addEventListener(type: String, listener: EventListenerOrEventListenerObject?, options: Boolean? = definedExternally /* null */)
    open fun addEventListener(type: String, listener: EventListenerOrEventListenerObject?, options: AddEventListenerOptions? = definedExternally /* null */)
    open fun dispatchEvent(evt: Event): Boolean
    open fun removeEventListener(type: String, listener: EventListenerOrEventListenerObject? = definedExternally /* null */, options: EventListenerOptions? = definedExternally /* null */)
    open fun removeEventListener(type: String, listener: EventListenerOrEventListenerObject? = definedExternally /* null */, options: Boolean? = definedExternally /* null */)
    open fun addEventListener(type: String, listener: EventListenerOrEventListenerObject?)
    open fun removeEventListener(type: String)
}

external interface WebSocketCallbackMap {
    var close: () -> Unit
    var error: (err: Error) -> Unit
    var message: (message: dynamic /* String | Blob | ArrayBuffer | ArrayBufferView */) -> Unit
    var open: () -> Unit
}

external open class WebSocket : EventTarget {
    constructor(url: String?, protocols: String?)
    constructor(url: String?, protocols: Array<String>?)
    open var url: String
    open var CONNECTING: String /* 0 */
    open var OPEN: String /* 1 */
    open var CLOSING: String /* 2 */
    open var CLOSED: String /* 3 */
    open var readyState: Number
    open var bufferedAmount: Number
    open var onopen: EventHandlerNonNull
    open var onerror: EventHandlerNonNull
    open var onclose: EventHandlerNonNull
    open var extensions: String
    open var protocol: String
    open fun close(code: Number? = definedExternally /* null */, reason: String? = definedExternally /* null */)
    open var onmessage: EventHandlerNonNull
    open var binaryType: BinaryType
    open fun send(data: String)
    open fun send(data: Blob)
    open fun send(data: ArrayBuffer)
    open fun send(data: ArrayBufferView)
    open fun <K : Any> on(type: K, callback: Any)

    companion object {
        var CONNECTING: String /* 0 */
        var OPEN: String /* 1 */
        var CLOSING: String /* 2 */
        var CLOSED: String /* 3 */
    }
}

external open class Server(url: String, options: ServerOptions? = definedExternally /* null */) : EventTarget {
    open var options: ServerOptions
    open fun start()
    open fun stop(callback: (() -> Unit)? = definedExternally /* null */)
    open fun on(type: String, callback: (socket: WebSocket) -> Unit)
    open fun close(options: CloseOptions? = definedExternally /* null */)
    open fun emit(event: String, data: Any, options: EmitOptions? = definedExternally /* null */)
    open fun clients(): Array<WebSocket>
    open fun to(room: Any, broadcaster: Any, broadcastList: Any? = definedExternally /* null */): ToReturnObject
    open fun `in`(any: Any): ToReturnObject
    open fun simulate(event: String)
    open fun of(url: String): Server
}

external interface CloseOptions {
    var code: Number
    var reason: String
    var wasClean: Boolean
}

external interface EmitOptions {
    var websockets: Array<WebSocket>
}

external interface ToReturnObject {
    var to: (chainedRoom: Any, chainedBroadcaster: Any) -> ToReturnObject
    fun emit(event: Event, data: Any)
}

external interface ServerOptions {
    var verifyClient: (() -> Boolean)?
        get() = definedExternally
        set(value) = definedExternally
    var selectProtocol: ((protocols: Array<String>) -> String?)?
        get() = definedExternally
        set(value) = definedExternally
}
And Intellij shows some missing imports
image.png
image.png
Oh, and this method should be a callback instead of Any:
Copy code
external open class WebSocket : EventTarget {
    /* */
    open fun <K : Any> on(type: K, callback: Any)
    /* */
}
Any idea how can I fix these errors or write down an issue?
i
@fcosta You can create an issue here - https://github.com/Kotlin/dukat/issues
Some of these problems were fixed in the new versions of Dukat. You can increase the version of Dukat in your
build.gradle
in
frontend
module.
Copy code
rootProject.kotlinNodeJs.versions.dukat.version = "0.0.25"
e
Dukat 0.0.26 has released, though it is far from usable out of the box. Most people use the dukat cli to generate definition files, and fix the errors manually.
If the above statement does not work, you can use this to upgrade your Dukat
Copy code
NodeJsRootPlugin.apply(project).run {
  versions.dukat.version = "0.0.26"
}
f
Unfortunately the error is still happening. I will open an issue for it! Thanks you! 😄