Hi all, i am trying to find a way to export suspen...
# javascript
l
Hi all, i am trying to find a way to export suspend function for js target, i have gone through multiple resources online but i am not able to find a way to do that the way i want. I want that
suspend fun foo(): String
should get converted to
foo(): Promise<string>;
in Js. From what i know there is no native support for this. I was able to reach a Js signature
fooAsync(): Promise<String>;
using kotlin-suspend-transform-compiler-plugin , but i would want to have the same signature(without async) as it would be easier for all 3 targets(android, ios and js) to follow the generated docs and use it. Is there a way to achieve this ? other obv option is to have duplicate exported api interfaces for only js, but i really don't wish to go that route. I was also thinking if this plugin or some other plugin could help me generate a synthetic function
Copy code
@JsExport
@JsName("foo")
fun fooSynthetic(): Promise<String> // generated synthetic function

@JsName("_foo")
suspend fun foo(): String // original function defined in api
If somehow above could be achieved, i was thinking it could work ? (Please correct me if my thought process is wrong here, i am new to KMP) Thanks.
e
The compiler plugin you mentioned supports modifying the generated suffix, see the
defaultSuffix
property if I'm not mistaken. You might want to experiment with an empty suffix and see what happens.
l
i had already tried empty suffix by using this annotation
@JsPromise(suffix = "")
but it doesn't work, because the synthetic kotlin function generated due to that will have same signature as the actual function(only differs on return type).
e
Honestly I'm out of ideas for this case as the predefined suffix wasn't a problem for me. In our main project tho we manually implement a wrapping layer as we don't want to depend on a compiler plugin that might have issues or slow down development.