Hey there, I have a problem with @OptIn annotation...
# multiplatform
m
Hey there, I have a problem with @OptIn annotation. Here is a sample code below: // commonMain
Copy code
expect interface TestCallback
// iosMain
Copy code
@OptIn(ExperimentalForeignApi::class)
actual typealias TestCallback = TestDelegateProtocol
There is a problem if I use TestCallback in commonMain package, it says: error: This declaration needs opt-in. Its usage must be marked with '@kotlinx.cinterop.ExperimentalForeignApi' or '@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)' At first, for @OptIn annotated types (classes, properties...), Its usages are not required to opt into that API (ExperimentalForeignApi) The second ExperimentalForeignApi is platform-specific, which means I can't use it on commonMain package. Does anybody have this kind of problem?
👀 1
I assume that was a dumb question _) As long as typealias uses cInterop generated class, that needs to be annotated. The misunderstanding part is the useless @OptIn annotation in this case. My hotfix is to wrap an object to the interface and use this interface instead. So typealias itself should not be annotated.
Copy code
interface TestDelegateProtocolProvider {
    @OptIn(ExperimentalForeignApi::class)
    fun provide(): TestDelegateProtocol
}