Open ScottPierce opened 3 years ago
I ended up exporting the declarations, adding their folder to the source set manually, and resolving the errors that way, but there were key problems in the resulting exported code that stopped it from working still:
@JsModule
declarations, so the even when I resolve the build problems, the types / code can't be found at runtime.Here is the definition of Observable
:
export class Observable<T> implements Subscribable<T> {
constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic) {
// ...
}
//...
}
Here is the definition dukat creates:
open external class Observable<T>(subscribe: (self: Observable<T>, subscriber: Subscriber<T>) -> dynamic = definedExternally) : Subscribable<T> {
// ...
}
And here is how Typescript has me use it:
new Observable<String>((subscriber) => {
//...
})
Typescript actually complains when I add a second parameter to the lambda. Perhaps there is a feature of typescript that allows this
to be set for the parameter when it's named this
? Either way, when I use the Kotlin version at runtime, the subscriber
parameter is incorrectly undefined
The first issue I mentioned seems to be referenced here I think - https://github.com/Kotlin/dukat/issues/263
this
parameters in function types describe what this
will be in that function. However that won't be the case if an arrow function is used.
The most natural way to express this in Kotlin would be to translate it to an extension function type, however I am not sure if the JS translation permits that, that extension function would have to be translated to a JS function
that uses the JS this
(instead of Kotlin's synthetic "receiver" parameter.
Using Kotlin 1.4.0
implementation(npm("rxjs", "6.6.3", generateExternals = true))
https://youtrack.jetbrains.com/issue/KT-41822
Here are the errors: