[JS/IR] fix: add ability to render type constraints into TypeScript definitions.
This commit is contained in:
@@ -81,7 +81,7 @@ data class ExportedRegularClass(
|
||||
val isAbstract: Boolean = false,
|
||||
override val superClass: ExportedType? = null,
|
||||
override val superInterfaces: List<ExportedType> = emptyList(),
|
||||
val typeParameters: List<String>,
|
||||
val typeParameters: List<ExportedType.TypeParameter>,
|
||||
override val members: List<ExportedDeclaration>,
|
||||
override val nestedClasses: List<ExportedClass>,
|
||||
override val ir: IrClass,
|
||||
|
||||
+1
-1
@@ -378,7 +378,7 @@ class ExportModelGenerator(
|
||||
members: List<ExportedDeclaration>,
|
||||
nestedClasses: List<ExportedClass>
|
||||
): ExportedDeclaration {
|
||||
val typeParameters = klass.typeParameters.map { it.name.identifier }
|
||||
val typeParameters = klass.typeParameters.map(::exportTypeParameter)
|
||||
|
||||
// TODO: Handle non-exported super types
|
||||
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ class ExportModelToTsDeclarations {
|
||||
}
|
||||
|
||||
val renderedTypeParameters = if (typeParameters.isNotEmpty()) {
|
||||
"<" + typeParameters.joinToString(", ") + ">"
|
||||
"<" + typeParameters.joinToString(", ") { it.toTypeScript(indent) } + ">"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
@@ -234,6 +234,10 @@ declare namespace JS_TESTS {
|
||||
function createNested1(): typeof foo.Parent.Nested1;
|
||||
function createNested2(): foo.Parent.Nested1.Nested2;
|
||||
function createNested3(): foo.Parent.Nested1.Nested2.Companion.Nested3;
|
||||
class GenericClassWithConstraint<T extends foo.TestInterface> {
|
||||
constructor(test: T);
|
||||
get test(): T;
|
||||
}
|
||||
}
|
||||
namespace _objects_ {
|
||||
const foo$Parent$Nested1: {
|
||||
|
||||
@@ -295,3 +295,6 @@ fun createNested2(): Parent.Nested1.Nested2 {
|
||||
fun createNested3(): Parent.Nested1.Nested2.Companion.Nested3 {
|
||||
return Parent.Nested1.Nested2.Companion.Nested3()
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class GenericClassWithConstraint<T: TestInterface>(val test: T)
|
||||
+3
@@ -37,6 +37,7 @@ var getParent = JS_TESTS.foo.getParent;
|
||||
var createNested1 = JS_TESTS.foo.createNested1;
|
||||
var createNested2 = JS_TESTS.foo.createNested2;
|
||||
var createNested3 = JS_TESTS.foo.createNested3;
|
||||
var GenericClassWithConstraint = JS_TESTS.foo.GenericClassWithConstraint;
|
||||
function assert(condition) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
@@ -150,5 +151,7 @@ function box() {
|
||||
assert(createNested1() === nested1);
|
||||
assert(createNested2() !== nested2);
|
||||
assert(createNested3() !== nested3);
|
||||
var genericClassInstance = new GenericClassWithConstraint(new TestInterfaceImpl("test"));
|
||||
assert(processInterface(genericClassInstance.test) == "Owner TestInterfaceImpl has value 'test'");
|
||||
return "OK";
|
||||
}
|
||||
|
||||
+5
@@ -37,6 +37,7 @@ import getParent = JS_TESTS.foo.getParent;
|
||||
import createNested1 = JS_TESTS.foo.createNested1;
|
||||
import createNested2 = JS_TESTS.foo.createNested2;
|
||||
import createNested3 = JS_TESTS.foo.createNested3;
|
||||
import GenericClassWithConstraint = JS_TESTS.foo.GenericClassWithConstraint;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
@@ -182,5 +183,9 @@ function box(): string {
|
||||
assert(createNested1() === nested1)
|
||||
assert(createNested2() !== nested2)
|
||||
assert(createNested3() !== nested3)
|
||||
|
||||
const genericClassInstance = new GenericClassWithConstraint(new TestInterfaceImpl("test"))
|
||||
assert(processInterface(genericClassInstance.test) == "Owner TestInterfaceImpl has value 'test'")
|
||||
|
||||
return "OK";
|
||||
}
|
||||
Reference in New Issue
Block a user