Hello,
In Kotlin/WasmJs, I've created a simple small function js wrapper:
Copy code
fun jsLocalStorageGetItem(key: String): String =
js("window.localStorage.getItem(key)")
If the key exist, no problem. If the key doesn't exist I have a
NullPointerException
on the browser console. I've try to add a
String?
as a return type
Copy code
fun jsLocalStorageGetItem(key: String): String? =
js("window.localStorage.getItem(key)")
But the compiler refuse this solution. Maybe I can get away with a try/catch (didn't try yet) but it seem odd to me we can't handle null value from calling js function...
Reginald Louis
03/29/2024, 1:50 PM
image.png
r
Robert Jaros
03/29/2024, 2:04 PM
Why the compiler refuses nullable return value for you? It works for me.