Last active
September 5, 2017 03:07
-
-
Save nosix/538b6bf673547f723cb547c83033fd54 to your computer and use it in GitHub Desktop.
union type in Kotlin/JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sample$lambda() { | |
return 'Bar'; | |
} | |
function sample() { | |
var v1 = 'Foo'; | |
var v2 = sample$lambda; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
external interface ObjectOrFactory<T> | |
inline fun <T> ObjectOrFactory(value: T): ObjectOrFactory<T> = value.asDynamic() | |
inline fun <T> ObjectOrFactory(value: () -> T): ObjectOrFactory<T> = value.asDynamic() | |
inline fun <T> ObjectOrFactory.toObject(): T = this.asDynamic() | |
inline fun <T> ObjectOrFactory.toFactory(): () -> T = this.asDynamic() | |
fun sample() { | |
val v1: ObjectOrFactory<String> = ObjectOrFactory("Foo") | |
val v2: ObjectOrFactory<String> = ObjectOrFactory { "Bar" } | |
// val v3: ObjectOrFactory<String> = "Buz" // error | |
// val v4: ObjectOrFactory<String> = ObjectOrFactory(100) // error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment