4 ms·
"For this function named `call`, the first argument must be a function `fn`, and subsequent arguments must be the type of arguments that `fn` expects. The retur
by brlewis 8y ago
"For this function named `call`, the first argument must be a function `fn`, and subsequent arguments must be the type of arguments that `fn` expects. The return value of `call` is the same type as the return value of `fn`."
How would you recommend communicating all that in an extended version of ECMAscript?
- frankpf 8y agoI like TypeScript's syntax, but I think the way function types are declared is ugly. 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); }
- eppsilon 8y agoThe syntax is probably meant to differentiate between a function expression and a function type declaration.