James Mulholland
10/28/2020, 5:38 PMJames Mulholland
10/28/2020, 5:40 PMexport namespace com.company.package.foo {
interface MyInterface {
foo(): void;
}
class SomeClass {
// ...
}
}
James Mulholland
10/28/2020, 5:43 PMimport Package from 'package';
Package.com.company.package.foo.SomeClass // good
Package.com.company.package.foo.MyInterface // bad
James Mulholland
10/28/2020, 5:44 PMJames Mulholland
10/28/2020, 5:45 PMimport * as Package from 'package'
import type Package from 'package'
James Mulholland
10/28/2020, 5:49 PM// importPackage.ts
import Package from 'package';
export const Foo = Package.com.company.package.foo;
// Another file...
import { Foo } from './importPackage'
const x: Foo.MyInterface; // not there!
Big Chungus
10/28/2020, 6:36 PMBig Chungus
10/28/2020, 6:36 PMBig Chungus
10/28/2020, 6:36 PMBig Chungus
10/28/2020, 6:41 PMimport Package from 'package';
let x: Package.com.company.package.MyInterface
James Mulholland
10/28/2020, 9:24 PMJames Mulholland
10/28/2020, 9:24 PMBig Chungus
10/28/2020, 9:25 PMJames Mulholland
10/28/2020, 9:25 PMJames Mulholland
10/28/2020, 9:25 PMJames Mulholland
10/28/2020, 9:25 PMBig Chungus
10/28/2020, 9:25 PMJames Mulholland
10/28/2020, 9:27 PMJames Mulholland
10/28/2020, 9:27 PMJames Mulholland
10/28/2020, 9:27 PMBig Chungus
10/28/2020, 9:27 PMJames Mulholland
10/28/2020, 9:27 PMBig Chungus
10/28/2020, 9:28 PMBig Chungus
10/28/2020, 9:28 PMJames Mulholland
10/28/2020, 9:28 PMJames Mulholland
10/28/2020, 9:28 PMBig Chungus
10/28/2020, 9:29 PMBig Chungus
10/29/2020, 10:15 AMX.name
, JS: X.get_name()
). This works fine if you mark your interfaces as external
James Mulholland
10/29/2020, 10:16 AMBig Chungus
10/29/2020, 10:24 AMJames Mulholland
10/29/2020, 10:24 AMBig Chungus
10/29/2020, 10:25 AMJames Mulholland
10/29/2020, 10:25 AMBig Chungus
10/29/2020, 10:25 AMinterface KMyInterface: MyInterface
James Mulholland
10/29/2020, 10:25 AMModifier 'external' is not applicable to 'class'
Big Chungus
10/29/2020, 10:25 AMJames Mulholland
10/29/2020, 10:26 AM@JsExport
external interface SessionPresenting {
fun presentLoading()
fun presentCard(card: Card, sessionProgress: SessionProgress)
fun presentSummary(bonusPoints: Int)
}
Big Chungus
10/29/2020, 10:26 AMBig Chungus
10/29/2020, 10:26 AMJames Mulholland
10/29/2020, 10:27 AMBig Chungus
10/29/2020, 10:27 AMBig Chungus
10/29/2020, 10:27 AMJames Mulholland
10/29/2020, 10:28 AMBig Chungus
10/29/2020, 10:28 AMval name:String
use fun getName(): String
Big Chungus
10/29/2020, 10:28 AMJames Mulholland
10/29/2020, 10:30 AMBeen playing around with this myself a bit. Here’s a working sample for you. Oddly enough, TS declarations generated for normal kotlin interfaces does not match backing JS, because declarations export interface properties as fields, where compiled js has them as getters (TS:I’m confused by this message. Do you mean to say Kotlin interfaces get exported as values, not types at some point?, JS:X.name
). This works fine if you mark your interfaces asX.get_name()
external
James Mulholland
10/29/2020, 10:31 AMBig Chungus
10/29/2020, 10:32 AMBig Chungus
10/29/2020, 10:32 AMJames Mulholland
10/29/2020, 10:33 AMBig Chungus
10/29/2020, 10:33 AMBig Chungus
10/29/2020, 10:33 AMJames Mulholland
10/29/2020, 10:33 AMJames Mulholland
10/29/2020, 10:33 AMJames Mulholland
10/29/2020, 10:33 AMBig Chungus
10/29/2020, 10:33 AMBig Chungus
10/29/2020, 10:34 AMHi
Hello from Martynas
Hello from Yo Mama
Hello from Should Still Work
Safe hello from Safe Word "fun"
CRASH, stack trace & etc... due to
var str = '' + 'Hello from ' + person._get_name__0() + ' ' + person._get_sureName__0();
^
TypeError: person._get_name__0 is not a function
James Mulholland
10/29/2020, 10:35 AMBig Chungus
10/29/2020, 10:35 AMJames Mulholland
10/29/2020, 10:36 AMBig Chungus
10/29/2020, 10:37 AMJames Mulholland
10/29/2020, 10:46 AMval
properties have those vals accessed using getters in the JS, but are exported as straightforward interfaces with properties in the .d.ts
file.
2. We can work around this by marking the class as external (e.g. here: https://gitlab.com/lt.petuska/npm-publish/-/blob/develop/sandbox/mpp/src/jsIRMain/kotlin/test/sandbox/index.kt#L22)
3. But external doesn’t work when functions on an interface take a class as one of the parameters
4. So a refactor to use getter functions instead of val
is neededJames Mulholland
10/29/2020, 10:46 AMBig Chungus
10/29/2020, 10:49 AMvar
too. Raised a YT to track.adk
10/30/2020, 8:24 AMBig Chungus
10/30/2020, 8:28 AM