Does anyone else have issues using a `dynamic` as ...
# compose-web
d
Does anyone else have issues using a
dynamic
as the type of a parameter in a composable function? (Stack trace in thread)
Copy code
@Composable
fun myComposable(value: dynamic) {
}
Copy code
java.lang.IllegalStateException: dynamic
	at org.jetbrains.kotlin.backend.jvm.ir.JvmIrTypeUtilsKt.getErasedUpperBound(JvmIrTypeUtils.kt:94)
	at org.jetbrains.kotlin.backend.jvm.ir.JvmIrTypeUtilsKt.isInlineClassType(JvmIrTypeUtils.kt:123)
	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer$Scope$FunctionScope.parameterInformation(ComposableFunctionBodyTransformer.kt:3503)
	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer$Scope$FunctionScope.calculateSourceInfo(ComposableFunctionBodyTransformer.kt:3558)
	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer.getSourceInformation(ComposableFunctionBodyTransformer.kt:1186)
	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer.applySourceFixups(ComposableFunctionBodyTransformer.kt:1196)
	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer.lower(ComposableFunctionBodyTransformer.kt:463)
	at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:167)
	at org.jetbrains.kotlin.ir.backend.js.KlibKt.generateModuleFragmentWithPlugins$lambda-26(klib.kt:456)
	at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:88)
	at org.jetbrains.kotlin.ir.backend.js.KlibKt.generateModuleFragmentWithPlugins(klib.kt:461)
	at org.jetbrains.kotlin.ir.backend.js.KlibKt.generateKLib(klib.kt:189)
	at org.jetbrains.kotlin.ir.backend.js.KlibKt.generateKLib$default(klib.kt:122)
	at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:264)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:178)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:71)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at org.jetbrains.kotlin.incremental.IncrementalJsCompilerRunner.runCompiler(IncrementalJsCompilerRunner.kt:193)
	at org.jetbrains.kotlin.incremental.IncrementalJsCompilerRunner.runCompiler(IncrementalJsCompilerRunner.kt:78)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:357)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:299)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:159)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:80)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile$default(IncrementalCompilerRunner.kt:71)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execJsIncrementalCompiler(CompileServiceImpl.kt:564)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execJsIncrementalCompiler(CompileServiceImpl.kt:100)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1802)
n
I haven't tried but I would try to wrap the
dynamic
reference in a simple wrapper class, and pass that wrapper class to the
@Composable fun
(instead of the
dynamic
directly). (And maybe file an issue, I haven't found any: https://youtrack.jetbrains.com/issues/KT?q=@Composable%20dynamic)
o
Yes, please file an issue. I think the issue can be created at https://github.com/JetBrains/compose-jb right away. By the way, what's your use cases for having dynamic type for a parameter of a composable?
👍 1
d
My use case is to wrap an existing js library in Compose (specifically mapbox-gl-js). Their expression system can take many types, and I have helper functions that apply a given expression to the actual map. Right now I'm getting away with using
Any?
but
dynamic
would be more correct. https://github.com/dellisd/reroute/blob/master/web/src/jsMain/kotlin/io/github/dellisd/reroute/map/LayerScope.kt#L20-L35
n
@Derek Ellis, have you tried wrapping the dynamic in a value/data class?
d
Yes, that does work (as does
Array<dynamic>
), it's just not ideal
b
Can't you use Any type instead?
dynamic is to be reserved as a last resort to shut compiler up
I personally don't think compose should even aim to support it, but instead throw a descriptive compiler error when detected
2
@Oleksandr Karpovich [JB] what do you think?
o
We discussed this briefly within a team. As Nikolai mentioned in the issue we'll likely disallow using dynamic as an argument of composable functions. It's better to define and use external interfaces instead.
👍🏻 1