How would you recommend communicating all that in an extended version of ECMAscript?
If you have a function from A to B, you have to declare its type as
type MyFunction = (arg1: A) => B
instead of type MyFunction = A => B
Here's that syntax applied to the example from GP: function call<TS extends any[], R>(fn: (...args: TS) => R, ...args: TS): R { return fn(...args); }
vs. function call<TS extends any[], R>(fn: ...TS => R, ...args: TS): R { return fn(...args); }This construct would actually be more complex if the parameter list types were actually specified instead of being any[].
I call code like this 'clever' as it uses the language constructs to get usually a very optimal end result at the behest of being harder for n00bs like myself to parse.
I do wonder what a prettier version of this would look like. It certainly wouldn't be this concise but would it be better or harder to follow? I'm okay with something like this if it solves a very specific problem I hardly see. If my entire code base is littered with this? No thanks. Yea eventually it'd be second nature but I'd rather it be more verbose and slightly easier to unpack than this tightly packed.
Secondly, the (...args: TS) => R can be extracted into another type/interface, this way you would just get "function call<TS extends any[], R>(fn: Callable<TS, R>, ...args: TS): R"