Open shicks opened 7 years ago
John has proposed ICallable<T>
for handling types that describe functions with properties, which we will add at some point. Then, you can rewrite this slightly modified, by currying the return function. I doubt that we'll implement this with the proposed syntax, b/c it's probably too specialized to justify the cost of supporting it.
/**
* @param {!ICallable<T>} func
* @return {function(number):!ICallable<T>}
* @template T
*/
function delayed(func) {
return function(time) {
return function(...args) {
setTimeout(func.bind(this, ...args), time);
}
};
}
I sometimes write functions that take arbitrary functions as arguments and return functions that expect the same (or slightly modified) types of parameters. Currently there's no way to do this without loosening the type information on the returned function. Some sort of template syntax (say,
*REST
, cribbing from python) could allow more precise matching:Another use cases is mixins (where the
@param
and@return
would be of the formfunction(new: T, *REST)
, again with the possibility of adding an extra parameter).