Sorry if I'm bothering, but I sometimes encounter ...
# javascript
h
Sorry if I'm bothering, but I sometimes encounter these "double types". For example TanStack Table has the
Updater
which is defined like this:
Copy code
sealed external interface Updater<T> /* T | ((old: T) -> T) */

inline fun <T> Updater(
    source: T,
): Updater<T> =
    unsafeSpecialCast(source)

inline fun <T> Updater(
    noinline source: (old: T) -> T,
): Updater<T> =
    unsafeSpecialCast(source)
I know I can create these using
functionalUpdate()
but how do I consume them? Currently I do
Copy code
this.onSortingChange = { newSorting ->
    setSorting(newSorting.unsafeCast<SortingState>())
}
but it feels kind of wrong. What is correct way to consume such an
Updater
?
e
Copy code
this.onSortingChange = Updater<SortingState> { newSorting ->
    setSorting(newSorting)
}
Does this work?
h
Sadly, no:
The compiler suggestion 😅
Okay this works, but it still doesn't look right this mimics the doc though (https://tanstack.com/table/v8/docs/guide/pagination):
Copy code
useReactTable<T>(
    options = jso {
        val (pagination, setPagination) = states.pagination // StateInstance<PaginationState>
        
        this.state = jso<TableState> {
            this.pagination = pagination
        }
        
        this.onPaginationChange = unsafeSpecialCast(setPagination) 
    }
)
t
We have invalid declaration for
Updater
in fact
If you use Kotlin Wrappers and you need
unsafeCast
or
asDynamic
: 1. Probably you need it without reason, please check one more time 2. It can be typization error in wrappers (current case)
@Hildebrandt Tobias could you please report the problem, I will fix it 😎
h
In YouTrack or Kotlin-Wrapper Issues?
t
Kotlin Wrappers please
h
Will do
t
Fix released in Kotlin Wrappers
2025.5.0
😎
😎 1