I'm getting this error after calling a fun that re...
# multiplatform
l
I'm getting this error after calling a fun that returns a Promise:
Unhandled Runtime Error TypeError: hidden._get_entries__31877249_iz8n5_k$ is not a function
browser request is responding 200 Any idea? The fun in js target:
Copy code
fun initialize (formId: String, hidden: Map<String, String>): Promise<InitializationResult> = GlobalScope.promise{ internalForm.initialize(formId, hidden)}
t
Are you calling from js or calling from kotlin? Js doesn't know what a map is
l
I'm calling from js (browser) What would be the ideal way to get around this? I can't use Map any time? even inside commonMain? the hidden parameter is dynamic :/
t
So if you are calling this function directly from JS (the function is annotated with JSExport), then you can not use a map directly no. If it is inside of commonMain and called from other Kotlin code you can use Maps
The solution here kind of depends on what you're looking to do as well as if this is part of shared code vs js specific code
For example if this is just for JS code you could use a Json instead of a Map https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-json/
but you lose the type safety of the value being a string
You could also instead have the param be an array of Pair<String,String> and then convert it to a Map internally
I don't know the context for what hidden is being used for, so that would probably also adjust the solution
You could also create a public MapBuilder function that returns a Map with whatever syntax you choose, and you could use that returned Map for this param
but essentially the issues is that JS doesn't know what a Kotlin Map is, and there isn't a direct simple translation
l
The parameter will be passed directly to an API call.. We decided to use Json and MutableMap here.
You clarified some things for me
Thank you so much
t
Happy to help. Kotlin/JS has some of the most unique behavior at the exposed API layer (JSExport, Collection types, etc) compared to Kotlin/JVM and Kotlin/Native, so I ran into a lot of things in the past around trying to make a multiplatform project feel uniform between Mobile and Web
🚀 1
🙌 1