Just confirming here, based on what I've seen in s...
# javascript
s
Just confirming here, based on what I've seen in several threads, there is currently no type-safe way to support Union Types in KotlinJS? I'm fine with just returning
dynamic
, but just wanted to confirm.
s
Correct
You can sometimes emulate union types in parameters of external functions using overloading:
Copy code
// .ts
function foo(x: string|number): void
// .kt
external fun foo(x: Double)
external fun foo(x: String)
💡 1
s
Yeah unfortunately the union type is the return type of a callback in a
var
u
can you use generic constraints?
s
Generic constraints can help with intersection types but not union types
u
dammit 🙂
s
Rust solved this problem nicely with the
Into
and
From
traits 😞