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
When providing a callback method that must meet a certain signature, often not all parameters need to be used in the callback body. If only the 2nd parameter is used, the 1st still needs to be given a name; If only the 3rd, the 1st and 2nd still need names.
A common convention in many programming language is to use an underscore as the name of unused parameters.
For example in Haskell:
foo::Int->Int->Int
foo 0 x = x
foo _ _ =1
and in Prolog:
foo(0,X,X).foo(Y,_,1) :-Y\=0.
This can of course be done in typescript but only for 1 parameter as parameters aren't allow to have duplicate names. #9464 allowed unneeded parameters to be prefixed with an underscore to work nicely with noUnusedParameters; however those parameters still need to each have a unique name.
Using _1, _2, _3 etc seems clunky to me.
I would like to suggest that parameter named _ be made exempt from the Duplicate identifier error.
The compiler could simply switch out multiple uses of _ for _1, _2, _3 etc.
Use Cases
When I write functional JavaScript, I always use an underscore to represent an unused parameter. This suggestion would be nice for function where there are more than 1 parameters that aren't being used in the function body.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Search Terms
Suggestion
When providing a callback method that must meet a certain signature, often not all parameters need to be used in the callback body. If only the 2nd parameter is used, the 1st still needs to be given a name; If only the 3rd, the 1st and 2nd still need names.
A common convention in many programming language is to use an underscore as the name of unused parameters.
For example in Haskell:
and in Prolog:
This can of course be done in typescript but only for 1 parameter as parameters aren't allow to have duplicate names. #9464 allowed unneeded parameters to be prefixed with an underscore to work nicely with
noUnusedParameters
; however those parameters still need to each have a unique name.Using
_1
,_2
,_3
etc seems clunky to me.I would like to suggest that parameter named
_
be made exempt from theDuplicate identifier
error.The compiler could simply switch out multiple uses of
_
for_1
,_2
,_3
etc.Use Cases
When I write functional JavaScript, I always use an underscore to represent an unused parameter. This suggestion would be nice for function where there are more than 1 parameters that aren't being used in the function body.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: