> Using inline classes as parameter type or ret...
# javascript
m
Using inline classes as parameter type or return type of external declarations is not supported
Noooo 😭 Will this limitation stay?
a
It probably will. How do you see that? Inline class should not exist in the runtime and you want to expose it to external API/
m
That makes inline classes unusable with Kotlin React as I need to pass them around between components in
RProps
.
a
Indeed. They should not be use with React. Use regular classes instead.
m
No. It’s just not possible to use them. That doesn’t mean they shouldn’t be used. It looks like an arbitrary limitation where there is no defined behavior yet.
a
You can't expose inline classes to the JavaScript. You can't use React without exposing props to JavaScript. Pretty straight-forward. You probably can use them with Kotlin-first React-like frameworks like Fritz2 for example
m
You keep saying that I can’t but don’t say why.
a
Because they do not exist in runtime
m
Yet I can use them in JVM.
a
JVM actually "uninlines" inline classes when you use them in "boxing" manner. It is not the best decision, but it works because of JVM specifics. It is not possible without runtime control over types.
m
In JS we could simply expose the underlying type.
a
In some cases. But in general it should not happen.
m
because…?
I already see myself ending up writing some weird wrapper around all React props to work around this 😮
a
because you can't separate inline class from its content in interop. The same problem as in JVM. It is probably possible to make it in some cases, but I think it is much easier to manually extract inline class content
m
Why would I have to separate it? Almost everything in JS is dynamic. Casting to
inline class
could be as dynamic as casting to an external type.
a
I am prety sure that inline classes work differently in IR and Legacy. For example in Legacy there is no inlining at all, so it won't work. Probably something could be done after inline stabilization/
m
I’ve added a feature request for this: https://youtrack.jetbrains.com/issue/KT-43224 For now I’ll probably just use a
Box
type for that.
t
@Marc Knaup In common case you can suppress any restriction and test if it really work or doesn’t work
m
True, but in this case it’s not defined whether the inline class value would be boxed or not, so this would be highly unstable, if it works at all
t
It works!
Ctrl + J
- show source code
On Win -
Ctrl + Shift + J
m
In that simple example maybe, yes. In a more complex project? Hmm. Between Kotlin versions? Probably not 😅
But interesting
I wonder how it’s represented
probably unboxed?
t
More supported features for external types - https://youtrack.jetbrains.com/issue/KT-42871
probably unboxed?
Looks like boxed