Did someone manage to use the d.ts of its Kotlin/J...
# javascript
g
Did someone manage to use the d.ts of its Kotlin/JS MPP? I do not manage to implement an interface named
LifecycleOwner
declared like that:
Copy code
export namespace com.company.core.livedata {
    class Lifecycle {
        constructor();
        readonly tags: kotlin.collections.MutableMap<string, any>;
        isStarted: boolean;
        start(): void;
        stop(): void;
        addStopObserver(block: () => void): void;
        notifyObserversStop(): void;
    }
}
export namespace com.company.core.livedata {
    interface LifecycleOwner {
        readonly lifecycle: com.company.core.livedata.Lifecycle;
    }
}
I just don’t manage to import it in pure React app (with typescript). I import the module like that:
Copy code
import * as companycore from 'companycore';
I can find
Lifecycle
class if I log the whole module:
Copy code
console.log("companycore", companycore)
But not the
LifecycleOwner
interface. Any idea?
b
To get Lyfecycle you need to do this:
Copy code
import * as com from "companycore"
const Lifecycle = com.company.core.livedata.Lifecycle; // Class

let x: com.company.core.livedata.LifecycleOwner // type declaration
g
I am not sure how to use
x
to implement a class with it, as I get the following error:
Copy code
'LifecycleOwner' refers to a value, but is being used as a type here.  TS2749


  > 17 | export class LifecyleComponent extends React.Component implements LifecycleOwner {

}
b
Looks like your generated *.d.ts are wrong then
There's a known bug where *.d.ts interfaces are getting messed up for non
external
kotlin interfaces. maybe try adding
external
to LifecyckeOwner?
g
I can actually use directly the whole reference !!! 😱
b
What do you mean?
g
This works and now I am required to add a
Lifecycle
property in the class!
Copy code
export class LifecyleComponent extends React.Component implements com.company.core.livedata.LifecycleOwner { }
Maybe there’s another way to alias an interface?
b
Ah, yes
Copy code
type LifecycleOwner = com.company.core.livedata.LifecycleOwner
g
Sweet ! 😮
t
@galex what about root export? https://youtrack.jetbrains.com/issue/KT-37710
g
@turansky That would be so much better! It’s really a mess right now, I don’t feel like Kotlin/JS is ready yet.
t
Feature isn’t released. And it means, that root export can be default (like in ScalaJS)
Otherwise export and import will be non-synchronous