Hi:smiley:, I'm trying to use <minecraft script fr...
# javascript
k
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:
Copy code
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:
Copy code
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:
Copy code
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?
Copy code
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:
Copy code
export class BlockProperties {
    static readonly 'active' = 'active';
    static readonly 'color' = 'color';
    static readonly 'direction' = 'direction';
    // ...
}
They are converted to:
Copy code
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
?
Copy code
val active: String = definedExternally
Are these bugs? How can I deal with them?🤔
t
1.
MinecraftItemTypes
Copy code
external object MinecraftItemTypes {
    val air: ItemType
    val apple: ItemType
}

inline val MinecraftItemTypes.itemBed: ItemType
    get() = asDynamic()["item.bed"]
2.
BlockProperties
In IR you can use Seskar unions or write declarations like generated (works in all platforms)
k
It's troublesome to manually process them... Will Dukat directly support it in the future?🤔
t
It’s troublesome to manually process them...
You can use Seskar 🙂
👍 1
Dukat is currently paused
e
👍 1
k
Thank you, I'll try it.👍