dukat icon indicating copy to clipboard operation
dukat copied to clipboard

Failing to translate correctly varargs in lambdas

Open Schahen opened this issue 5 years ago • 2 comments

Consider following declaration:

 declare function ping(func: (...str: Array<string>) => boolean)

which is translated to:

external fun ping(func: (str: Array<String>) -> Boolean)

Which contradicts to what typescript code was purposed to. Unfortunately it's hard to think of workaround right now since we don't have varargs in lambdas.

Schahen avatar Jun 29 '20 17:06 Schahen

This goes for normal arrays too:

consoleCommand: (name: string, ...args: string[]) => void;

makes

var consoleCommand: (name: String, args: String) -> Unit

Which is totally wrong. From here: https://github.com/altmp/altv-types/blob/master/client/index.d.ts#L68

7Hazard avatar Nov 24 '20 23:11 7Hazard

We were able get the rest parameters as an array like the following:

val args: Array<String> = js("Array.prototype.slice.call(arguments, 1);")

7Hazard avatar Nov 25 '20 16:11 7Hazard