Why this Kotlin/js react code cannot compile?

45 Views Asked by At

Why this Kotlin/js react code cannot compile? It seems that type inference does not work well. I just want to add some more complex object to Context, but looks like type inference failed to work.

package xyz.nietongxue.diagramDsl.demo

import react.*
import react.dom.html.ReactHTML.div

typealias Cell = String
typealias Graph = String

typealias GS<T> = Pair<T, StateSetter<T>?>

typealias MultiGS2<A, B> = Pair<GS<A>, GS<B>>
typealias Selection = List<Cell>

val uiContext: Context<MultiGS2<Selection, Graph?>> =
//val uiContext: Context<Pair<GS<Selection>, GS<Graph?>>> =
    createContext(Pair(emptyList<Cell>() to null, null to null))

val selectionContext: Context<GS<Selection>> = createContext(emptyList<Cell>() to null)
val graphContext: Context<GS<Graph?>> = createContext(null to null)

val App = FC<Props> {

    var (selection, setSelection) = useState<List<Cell>>(emptyList())
    var (graph, setGraph) = useState<Graph?>(null)

//    uiContext.Provider{ //Here does not compile, and IDE inferences as  this:Nothing
//    value = Pair(selection, setSelection) to Pair(graph, setGraph) 
    selectionContext.Provider { //But this compiles.
        value = selection to setSelection //But this compiles.
        graphContext.Provider { //But this compiles.
            value = graph to setGraph //But this compiles.
            div {
                +"Hello, world!"
            }
        }
    }
}

Here are some version info:

val kotlinWrappersVersion = "1.0.0-pre.521"


plugins {
    val kotlinVersion = "1.8.20"
    kotlin("multiplatform") version "1.8.20"
...

  dependencies {
                implementation(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))
                implementation(kotlinw("react"))
                implementation(kotlinw("react-dom"))
0

There are 0 best solutions below