# javascript

Edoardo Luppi

03/01/2024, 6:59 PM
Given the following externals:
Copy code
typealias Done = (err: Any? /* use undefined for default */) -> Unit
typealias Func = (/* this: Context, */ done: Done) -> Unit

external class Test : Runnable {
  constructor(title: String, fn: Func)
And this usage:
Copy code
val fn: Func = {
suite.addTest(Test("example", fn))
The outputted code for
val fn: Func
Copy code
return function (it) {
  return Unit_getInstance();
Note the
argument is present even if it's not used. This is problematic when the JS code checks the number of arguments of the function. Should the JS compiler get rid of unused arguments like in this case?


03/01/2024, 7:02 PM
Seems like you could make the exact same argument if unused arguments were removed, as it equally could affect usage where the number of arguments of a function are significant.
I don't really see how this would be possible especially in the presence of separate compilation units for those things. Seems like you should define another lambda signature which has zero arguments.

Edoardo Luppi

03/01/2024, 7:05 PM
An additional lambda signature was my second option since there are many of them with this issue. But you're right, removing or not an argument should probably be an explicit choice, done by whoever writes the external declarations.
Btw, with additional signatures you end up with a lot of