Hi everyone :slightly_smiling_face: I'm new to Kot...
# javascript
t
Hi everyone 🙂 I'm new to Kotlin/JS, and I'm following the docs. I was testing how I could work with jQuery in kotlin. I followed this steps: https://kotlinlang.org/docs/reference/js-external-declarations-with-dukat.html
Copy code
implementation(npm("jquery", "3.5.1"))
implementation(npm("@types/jquery", "3.5.1", generateExternals = true))
However, I got a bunch of compile errors when running gradlew run, errors like:
'addEventListener' overrides nothing
'addEventListener' overrides nothing
'addEventListener' overrides nothing
'addEventListener' overrides nothing
'removeEventListener' overrides nothing
'removeEventListener' overrides nothing
Can dukat not yet convert declarations from @types/jquery 3.5.1? How then can I use jQuery in kotlin (with declarations)?
r
Dukat is still an experimental tool. It just doesn't work perfectly.
t
Nice, I'll check it out, thanks 🙂
j
t
The compilation error was different from the one in the issue, but maybe it's related. It was actually printing more than 500 errors, most referenced missing or unexpected overrides...
It works with a simple DefinitelyTyped library e.g.
is-odd
j
Ah right, it looks like it's the reverse problem.
override
modifiers when they should not be present (or missing interface most likely). Well as @Robert Jaros said, the project still has a bunch of quirks. What you can do as well is generate your externals "manually" using the
jsGenerateExternals
  gradle task, and then fix the declarations yourself by hand.
t
https://github.com/rjaros/jquery-kotlin doesn't really seem to work. jQuery.now() works but jQuery("#root") gives compiler error
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch
I've also tried jQuery declaration files from https://github.com/kotlin/js-externals, following the deprecation error message when defining
external fun jQuery(selector: String): JQuery
, but the run task gives an error that, to me, looks like it isn't prepared for IR compiler.
@Joffrey, I will try your solution, thanks
I'm getting hundreds of errors in translated files... 😕
r
@Tiago Nunes
Copy code
import pl.treksoft.jquery.jQuery
import pl.treksoft.jquery.invoke
🎉 1
t
@Robert Jaros that was it! IntelliJ didn't suggest me that import, which is weird right? It usually finds the imports for extension functions... maybe it's because it's an inline operator?
r
In the earlier version it was an operator inside an external interface with a
@nativeInvoke
annotation (which was working fine with auto-import). But it was deprecated and the inline extension function is a suggested change. https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/js/src/kotlin/annotations.kt#L18 Unfortunately it doesn't work nice with auto-imports.
👍 1