You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing some functional code and finding myself wanting a few type operators to smooth things over. They could also be used to type Function#apply, Function#call, etc. Since they're pretty closely related I'll just make one suggestion—if that doesn't work out, my bad.
argsof <func>
A tuple for the arguments taken by the function, for use with the spread operator or Function#apply. Using this on a non-function is illegal. If an argument is optional, the type just has | undefined added. (What about rest parameters? Maybe rest parameters could be added to tuples, as a way to override the default behavior of unioning all the member types. But that's a separate suggestion.)
returnof <func>
The type of the function's return value. Using this on a non-function is illegal.
This results in a call which takes a number, a string and a number as arguments. Those arguments aren't actually directly accessible to the function, since they don't have names -- they can be reached from the arguments object.
My main use for all of these is to mimic an existing function type dynamically, like this:
I'm writing some functional code and finding myself wanting a few type operators to smooth things over. They could also be used to type
Function#apply
,Function#call
, etc. Since they're pretty closely related I'll just make one suggestion—if that doesn't work out, my bad.argsof <func>
A tuple for the arguments taken by the function, for use with the spread operator or
Function#apply
. Using this on a non-function is illegal. If an argument is optional, the type just has| undefined
added. (What about rest parameters? Maybe rest parameters could be added to tuples, as a way to override the default behavior of unioning all the member types. But that's a separate suggestion.)returnof <func>
The type of the function's return value. Using this on a non-function is illegal.
Spread operator in function types
This results in a
call
which takes a number, a string and a number as arguments. Those arguments aren't actually directly accessible to the function, since they don't have names -- they can be reached from thearguments
object.My main use for all of these is to mimic an existing function type dynamically, like this:
The text was updated successfully, but these errors were encountered: