From 53753ce9f537ea639af99ece1ca5cfb3cc4f88d6 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sun, 22 Nov 2026 05:12:23 -0300 Subject: [PATCH] fix(runtime): pass a TypeScript constructor's arguments to the Java constructor TypeScript compiles a class without a constructor to `_super.apply(this, arguments) || this`. The helpers concatenated the arguments object into the argument list instead of its elements, so the Java constructor received a single Arguments object and creating the instance with any argument threw "Cannot marshal JavaScript argument". --- .../assets/app/tests/testsForTypescript.js | 21 +++++++++++++++++++ .../src/main/assets/internal/ts_helpers.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/test-app/app/src/main/assets/app/tests/testsForTypescript.js b/test-app/app/src/main/assets/app/tests/testsForTypescript.js index ae80690ec..34b586d5b 100644 --- a/test-app/app/src/main/assets/app/tests/testsForTypescript.js +++ b/test-app/app/src/main/assets/app/tests/testsForTypescript.js @@ -235,6 +235,27 @@ describe("Tests typescript", function () { expect(isInstanceOf).toEqual(true); }); + it("When_a_typescript_class_without_a_constructor_is_created_with_arguments_it_should_pass_them_to_the_java_constructor", function () { + + // TypeScript's output for `class NamedThread extends java.lang.Thread {}`. + var NamedThread = (function (_super) { + __extends(NamedThread, _super); + function NamedThread() { + return _super !== null && _super.apply(this, arguments) || this; + } + NamedThread.prototype.run = function () { + }; + return NamedThread; + })(java.lang.Thread); + + var thread = new NamedThread("named"); + expect(thread instanceof NamedThread).toBe(true); + expect(thread.getName()).toBe("named"); + + var unnamed = new NamedThread(); + expect(unnamed instanceof NamedThread).toBe(true); + }); + it("When_creating_a_typescript_instance_it_should_support_member_access", function () { __log("TEST: When_creating_a_typescript_instance_it_should_support_member_access"); diff --git a/test-app/app/src/main/assets/internal/ts_helpers.js b/test-app/app/src/main/assets/internal/ts_helpers.js index d1860dc47..5f187f94c 100644 --- a/test-app/app/src/main/assets/internal/ts_helpers.js +++ b/test-app/app/src/main/assets/internal/ts_helpers.js @@ -91,7 +91,7 @@ var Extended = extend(thiz); thiz.__container__ = true; if (args && args.length > 0) { - thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args))); + thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(args)))); } else { thiz.__proto__ = new Extended();