From a17730321646dc6fd24fb56973f518abef351ae9 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Tue, 14 Apr 2020 17:45:18 +0300 Subject: [PATCH] Strict contract for 'buildElement' --- kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt | 2 +- kotlin-react/src/main/kotlin/react/RBuilder.kt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt b/kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt index d8910b8b60503..cf31f80b68bd3 100644 --- a/kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt +++ b/kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt @@ -17,7 +17,7 @@ external interface JsObject { fun propertyIsEnumerable(v: String): Boolean } -fun Any.asJsObject() = this as JsObject +fun Any.asJsObject() = unsafeCast() external object Object { fun getPrototypeOf(o: T): P? diff --git a/kotlin-react/src/main/kotlin/react/RBuilder.kt b/kotlin-react/src/main/kotlin/react/RBuilder.kt index 5f9ff8036f75e..7961ce70e34fc 100644 --- a/kotlin-react/src/main/kotlin/react/RBuilder.kt +++ b/kotlin-react/src/main/kotlin/react/RBuilder.kt @@ -85,8 +85,10 @@ fun buildElements(handler: RBuilder.() -> Unit): dynamic { open class RBuilderSingle : RBuilder() -inline fun buildElement(handler: RBuilder.() -> Unit): ReactElement? = - RBuilder().apply(handler).childList.first() as ReactElement? +inline fun buildElement(handler: RBuilder.() -> Unit): ReactElement = + RBuilder().apply(handler) + .childList.first() + .unsafeCast() open class RElementBuilder(open val attrs: P) : RBuilder() { fun attrs(handler: P.() -> Unit) {