Skip to content

Instantly share code, notes, and snippets.

@nosix nosix/generated_sample.js
Last active Sep 5, 2017

Embed
What would you like to do?
union type in Kotlin/JS
function sample$lambda() {
return 'Bar';
}
function sample() {
var v1 = 'Foo';
var v2 = sample$lambda;
}
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
You can’t perform that action at this time.