Setting fillStyle on Canvas using new WASM issue

I am trying to set fillStyle on a HTML Canvas using the new KotlinWASM.

If I pass a string - I get a compiler error. If I force it to Dynamic (to pass typing), I get the browser crashing say the passed value is opaque.

** Compile Error (when String is passed)**
file:///Development/wasmMandlebrot/src/wasmMain/kotlin/canvas.kt:9:42 Type mismatch: inferred type is String but Dynamic? was expected

Browser Error (when Dynamic is passed)
Uncaught (in promise) TypeError: WebAssembly objects are opaque
at org.w3c.dom.fillStyle_$external_prop_setter_-1690691820 (wasmMandlebrot-wasm.uninstantiated.mjs?c843:3322:1)

** The code **

In essence its a ctx.fillStyle = “rgb(r,g,b)”

Is this me, or is this just because I am playing with Alpha software?

Gareth

This is a pre-alpha software issue. org.w3c.* are auto-generated and a not yet well tested. The issue is that passing Kotlin types likes numbers or strings doesn’t work when Dyanmic type is specified: https://youtrack.jetbrains.com/issue/KT-57136/K-Wasm-Restrict-non-external-types-in-JS-interop

A workaround would be to write a separate external function and use String type there directly. It could be a separate external interface member or a top-level function with `@JsFun(“code”):

@JsFun("x => x")
external fun stringToDynamic(x: String): Dynamic

Thanks for coming back so fast. Realise I am playing with early software.

Thanks for help - that hack worked perfectly (as you can see in updated repository).