Joffrey
09/04/2021, 5:08 PMwindow
but it's always non-null in Kotlin, it just fails at runtime on NodeJS.Derek Ellis
09/04/2021, 5:12 PMunsafeCast
it to something nullable, or wrap it in a try/catch?Joffrey
09/04/2021, 5:16 PMReferenceError
I didn't even think of catching it to be honest... but catch(Throwable)
does work. Good point. I was hoping for something more built-in though, as part of the Kotlin JS stdlibhfhbd
09/04/2021, 5:58 PMpublic actual val IS_BROWSER: Boolean = js(
"typeof window !== 'undefined' && typeof window.document !== 'undefined'"
) as Boolean
public actual val IS_NODE: Boolean = js(
"typeof process !== 'undefined' && process.versions != null && process.versions.node != null"
) as Boolean
Joffrey
09/04/2021, 6:00 PMReferenceError
to me 🙂 but still it would be great if that was in the stdlibhfhbd
09/04/2021, 6:01 PMJoffrey
09/04/2021, 6:02 PM