Alternative to @nativeGetter

I have a use case that seems to require @nativeGetter, but that annotation is deprecated.

I have this:

external class LoaderResults {
    @nativeGetter operator fun get(resource: String): LoaderResult?
}

interface LoaderResult {
    val name: String
    val error: Error?
}

What’s the recommended non-deprecated approach?

I believe it should be:

external class LoaderResults
inline fun LoaderResults.get(resource: String): LoaderResults? = asDynamic().get(resource)

See nativeGetter - Kotlin Programming Language

1 Like

You also have to add operator modifier and use asDynamic()[resource] instead of asDynamic().get(resource)

external class LoaderResults
inline operator fun LoaderResults.get(resource: String): LoaderResults? = asDynamic()[resource]