@nativeInvoke is deprecated
export interface SomeInterface {
(x: any, y: any): boolean;
}
produce:
external interface SomeInterface {
@nativeInvoke // 'nativeInvoke' is deprecated. Use inline extension function with body using dynamic
operator fun invoke(x: Any, y: Any): Boolean
}
Well, @nativeInvoke is the only way to translate this correctly in my understanding so I'd rather investigate how to supress this warning for this particular declarations.
Isn't it a problem of Kotlin JS than? I mean @nativeInvoke is deprecated, but it should be possible somehow to use this external interface without warnings from Kotlin JS Maybe make sense to create an issue on Kotlin issue tracker?
It's not related with this issue, but I post it here (don't know how to name it)
export function getter<T>(_this: any, propertyValue: T | { (): T }): T;
external interface `T$1` {
@nativeInvoke
operator fun invoke(): T /* --- Error: Unresolved reference: T --- */
}
external fun <T> getter(_this: Any, propertyValue: T): T
external fun <T> getter(_this: Any, propertyValue: `T$1`): T
@Schahen such callable Interface don't work for me (or maybe I don't understand how to use it in Kotlin). I have such d.ts:
export interface Template {
(): string;
}
generated Kotlin declarations is:
external interface Template {
@nativeInvoke
operator fun invoke(): String
}
But such code don't work for me:
val prop: Template = object : Template {
override fun invoke() = "text"
}
But such code works as expected:
typealias Template = () -> String
val prop: Template = () -> "text"
This seems to work as expected:
external interface SomeInterface
inline operator fun SomeInterface.invoke(x: Any, y: Any): Boolean {
return asDynamic()(x, y).unsafeCast<Boolean>()
}
I'm running into this warning as well. Can anyone point me to some resource explaining why this is deprecated?
I have a similar TS declaration, but on top of that it uses optional parameters:
declare const SockJS: {
new (url: string, _reserved?: any, options?: SockJS.Options): WebSocket;
(url: string, _reserved?: any, options?: SockJS.Options): WebSocket;
// ... other stuff
};
Dukat generates this:
external object SockJS {
@nativeInvoke
operator fun invoke(url: String, _reserved: Any = definedExternally, options: Options = definedExternally): WebSocket
// ... other stuff
}
I don't believe it's even possible to use the inline extension approach with definedExternally default values. Does that mean I should declare all overloads manually myself?